diff --git a/BDSM/models.py b/BDSM/models.py index 5d772f7..12833a2 100644 --- a/BDSM/models.py +++ b/BDSM/models.py @@ -56,10 +56,12 @@ class Tag(db.Model): name = db.Column(db.Text) class Emoji(db.Model): - shortcode = db.Column(db.Text, primary_key=True) + __table_args__ = {'sqlite_autoincrement': True} + emoji_id = db.Column(db.Integer, primary_key=True) + shortcode = db.Column(db.Text) + acct = db.Column(db.Text) url = db.Column(db.Text) static_url = db.Column(db.Text) - name = db.Column(db.Text) count = db.Column(db.Integer) class Media(db.Model): diff --git a/BDSM/static/css/style.css b/BDSM/static/css/style.css index 70fa4af..a3ccd79 100644 --- a/BDSM/static/css/style.css +++ b/BDSM/static/css/style.css @@ -40,6 +40,21 @@ body { .pagination span { padding-right: 10px; } + +.emojione { + width: 20px; + height: 20px; + margin: -3px 0 0; +} + +.emojione:hover { +z-index: 11; +/* Scale up 2.3 times */ +transform: scale(2.3); +/* shadows around image edges */ +filter: drop-shadow(0 0 1px #282c37); +} + .icon-bar span { padding-right: 10px; } diff --git a/BDSM/toot.py b/BDSM/toot.py index 1602248..de8e012 100644 --- a/BDSM/toot.py +++ b/BDSM/toot.py @@ -112,21 +112,34 @@ def archive_toot(url): if status['emojis'] != []: emoji_list = "" + for emoji in status['emojis']: shortcode = emoji['shortcode'] emoji_list += shortcode + "," counter = ':' + shortcode + ':' count = content.count(counter) - data=Emoji.query.filter_by(shortcode=shortcode).first() - if data is None: - emoji_data = Emoji(shortcode=shortcode, url=emoji['url'], static_url=emoji['static_url'], count=count) - db.session.add(emoji_data) - # cur.execute('''INSERT INTO EMOJI (shortcode,url,static_url,count) \ - # VALUES (?,?,?,?)''', (shortcode, emoji['url'], emoji['static_url'], count)) + if not is_reblog: + data=Emoji.query.filter_by(shortcode=shortcode).first() + if data is None: + emoji_data = Emoji(shortcode=shortcode, + acct=acct, + url=emoji['url'], + static_url=emoji['static_url'], + count=count) + db.session.add(emoji_data) + # cur.execute('''INSERT INTO EMOJI (shortcode,url,static_url,count) \ + # VALUES (?,?,?,?)''', (shortcode, emoji['url'], emoji['static_url'], count)) + else: + data.count += count + # cur.execute("UPDATE EMOJI SET count = ? WHERE shortcode = ?",(count, shortcode)) else: - data.count += count - # cur.execute("UPDATE EMOJI SET count = ? WHERE shortcode = ?",(count, shortcode)) + emoji_data = Emoji(shortcode=shortcode, + acct=acct, + url=emoji['url'], + static_url=emoji['static_url']) + + db.session.merge(emoji_data) else: emoji_list = "" @@ -170,7 +183,6 @@ def archive_toot(url): table.favourites_count=favourites_count table.language=language - db.session.add(table) # sql = f'''INSERT OR REPLACE INTO {table} (id,url,created_at,edited_at,in_reply_to_id,in_reply_to_account_id,content,\ # media_list,spoiler_text,poll_id,emoji_list,visibility,reblogged,favourited,bookmarked,sensitive,reblogs_count,\ diff --git a/BDSM/views.py b/BDSM/views.py index 8eae219..41174e9 100644 --- a/BDSM/views.py +++ b/BDSM/views.py @@ -3,9 +3,10 @@ import os from flask import render_template, request, url_for, redirect, flash from BDSM import app, db -from BDSM.models import Media, Settings, Toot +from BDSM.models import Media, Settings, Toot, Emoji from BDSM.toot import app_register, archive_toot from mastodon import Mastodon +from types import SimpleNamespace @app.route('/', methods=['GET', 'POST']) def index(): @@ -13,7 +14,8 @@ def index(): toots_ = Toot.query.order_by(Toot.created_at.desc()).paginate(page, per_page=50) toots = [] - for toot in toots_.items: + for toot_ in toots_.items: + toot = SimpleNamespace(**toot_.__dict__) if toot.content == None: continue @@ -27,6 +29,22 @@ def index(): if media != None: toot.medias.append(media) + if toot.emoji_list != "": + toot.emojis = [] + #emoji_list "blobfoxaaa,blobcatwww,fox_think," + emoji_list = toot.emoji_list[:-1].split(",") + + for emoji_shortcode in emoji_list: + emoji = Emoji.query.filter_by(shortcode=emoji_shortcode, acct=toot.acct).first() + + if emoji != None: + emoji_shortcode = ':' + emoji_shortcode + ':' + emoji_url = emoji.url + emoji_html = f''' + {emoji_shortcode} + ''' + toot.content = toot.content.replace(emoji_shortcode, emoji_html) + toots.append(toot) return render_template('view.html', toots=toots, pagination=toots_) diff --git a/Pipfile b/Pipfile index 4ee68b1..4ee5f06 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,8 @@ name = "pypi" flask = "*" flask-sqlalchemy = "*" python-dotenv = "*" +ptvsd = "*" +debugpy = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index e5802eb..726a170 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "5c49bdfaa2bb333c4af5bc5fa02d920a87c2d429460948ade1295a11dbac6a95" + "sha256": "b9112528b67d14410068a67ded8bf4770b845b9485939f627375fe3215202463" }, "pipfile-spec": 6, "requires": { @@ -47,6 +47,30 @@ "markers": "python_version >= '3.7'", "version": "==8.1.3" }, + "debugpy": { + "hashes": [ + "sha256:34d2cdd3a7c87302ba5322b86e79c32c2115be396f3f09ca13306d8a04fe0f16", + "sha256:3c9f985944a30cfc9ae4306ac6a27b9c31dba72ca943214dad4a0ab3840f6161", + "sha256:4e255982552b0edfe3a6264438dbd62d404baa6556a81a88f9420d3ed79b06ae", + "sha256:5ad571a36cec137ae6ed951d0ff75b5e092e9af6683da084753231150cbc5b25", + "sha256:6efc30325b68e451118b795eff6fe8488253ca3958251d5158106d9c87581bc6", + "sha256:7c302095a81be0d5c19f6529b600bac971440db3e226dce85347cc27e6a61908", + "sha256:84c39940a0cac410bf6aa4db00ba174f973eef521fbe9dd058e26bcabad89c4f", + "sha256:86d784b72c5411c833af1cd45b83d80c252b77c3bfdb43db17c441d772f4c734", + "sha256:adcfea5ea06d55d505375995e150c06445e2b20cd12885bcae566148c076636b", + "sha256:b8deaeb779699350deeed835322730a3efec170b88927debc9ba07a1a38e2585", + "sha256:c4b2bd5c245eeb49824bf7e539f95fb17f9a756186e51c3e513e32999d8846f3", + "sha256:c4cd6f37e3c168080d61d698390dfe2cd9e74ebf80b448069822a15dadcda57d", + "sha256:cca23cb6161ac89698d629d892520327dd1be9321c0960e610bbcb807232b45d", + "sha256:d5c814596a170a0a58fa6fad74947e30bfd7e192a5d2d7bd6a12156c2899e13a", + "sha256:daadab4403427abd090eccb38d8901afd8b393e01fd243048fab3f1d7132abb4", + "sha256:dda8652520eae3945833e061cbe2993ad94a0b545aebd62e4e6b80ee616c76b2", + "sha256:e8922090514a890eec99cfb991bab872dd2e353ebb793164d5f01c362b9a40bf", + "sha256:fc233a0160f3b117b20216f1169e7211b83235e3cd6749bcdd8dbb72177030c7" + ], + "index": "pypi", + "version": "==1.6.3" + }, "decorator": { "hashes": [ "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330", @@ -209,6 +233,37 @@ "index": "pypi", "version": "==1.5.1" }, + "ptvsd": { + "hashes": [ + "sha256:10745fbb788001959b4de405198d8bd5243611a88fb5a2e2c6800245bc0ddd74", + "sha256:1d3d82ecc82186d099992a748556e6e54037f5c5e4d3fc9bba3e2302354be0d4", + "sha256:20f48ffed42a6beb879c250d82662e175ad59cc46a29c95c6a4472ae413199c5", + "sha256:22b699369a18ff28d4d1aa6a452739e50c7b7790cb16c6312d766e023c12fe27", + "sha256:2bbc121bce3608501998afbe742f02b80e7d26b8fecd38f78b903f22f52a81d9", + "sha256:3b05c06018fdbce5943c50fb0baac695b5c11326f9e21a5266c854306bda28ab", + "sha256:3f839fe91d9ddca0d6a3a0afd6a1c824be1768498a737ab9333d084c5c3f3591", + "sha256:459137736068bb02515040b2ed2738169cb30d69a38e0fd5dffcba255f41e68d", + "sha256:58508485a1609a495dd45829bd6d219303cf9edef5ca1f01a9ed8ffaa87f390c", + "sha256:612948a045fcf9c8931cd306972902440278f34de7ca684b49d4caeec9f1ec62", + "sha256:70260b4591c07bff95566d49b6a5dc3051d8558035c43c847bad9a954def46bb", + "sha256:72d114baa5737baf29c8068d1ccdd93cbb332d2030601c888eed0e3761b588d7", + "sha256:90cbd082e7a9089664888d0d94aca760202f080133fca8f3fe65c48ed6b9e39d", + "sha256:92d26aa7c8f7ffe41cb4b50a00846027027fa17acdf2d9dd8c24de77b25166c6", + "sha256:b9970e3dc987eb2a6001af6c9d2f726dd6455cfc6d47e0f51925cbdee7ea2157", + "sha256:c01204e3f025c3f7252c79c1a8a028246d29e3ef339e1a01ddf652999f47bdea", + "sha256:c893fb9d1c2ef8f980cc00ced3fd90356f86d9f59b58ee97e0e7e622b8860f76", + "sha256:c97c71835dde7e67fc7b06398bee1c012559a0784ebda9cf8acaf176c7ae766c", + "sha256:ccc5c533135305709461f545feed5061c608714db38fa0f58e3f848a127b7fde", + "sha256:cf09fd4d90c4c42ddd9bf853290f1a80bc2128993a3923bd3b96b68cc1acd03f", + "sha256:d2662ec37ee049c0f8f2f9a378abeb7e570d9215c19eaf0a6d7189464195009f", + "sha256:d9337ebba4d099698982e090b203e85670086c4b29cf1185b2e45cd353a8053e", + "sha256:de5234bec74c47da668e1a1a21bcc9821af0cbb28b5153df78cd5abc744b29a2", + "sha256:eda10ecd43daacc180a6fbe524992be76a877c3559e2b78016b4ada8fec10273", + "sha256:fad06de012a78f277318d0c308dd3d7cc1f67167f3b2e1e2f7c6caf04c03440c" + ], + "index": "pypi", + "version": "==4.3.2" + }, "python-dateutil": { "hashes": [ "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86",