Skip to content

Commit

Permalink
Updated os specific thumbnail generation function to be cross platfor…
Browse files Browse the repository at this point in the history
…m, misc code changes/cleanup
  • Loading branch information
cc-d committed Dec 22, 2019
1 parent 98a6db3 commit f1e5bed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/config.py
Expand Up @@ -22,10 +22,10 @@
# This will be unique every time create_db.py is ran when testing
# to force clear sessions

SECRET_KEY = 'not-a-real-key-|r|zKTc5sjF3x|r|'
SECRET_KEY = 'not-a-real-key-|r|Zuyt_p-5Us|r|'

# Change this to your local URL. IE http://127.0.0.1
URL = 'http://127.0.0.1'
URL = 'http://dev.ieddit.com'

SQLALCHEMY_TRACK_MODIFICATIONS = False

Expand Down
10 changes: 8 additions & 2 deletions app/ieddit.py
Expand Up @@ -11,6 +11,10 @@
from bs4 import BeautifulSoup
import urllib.parse

import utilities.get_thumbnail

from threading import Thread

abs_path = os.path.abspath(os.path.dirname(__file__))
os.chdir(abs_path)
app.static_folder = 'static'
Expand Down Expand Up @@ -1052,9 +1056,11 @@ def create_post(api=False, *args, **kwargs):
db.session.add(new_post)
db.session.commit()

# Forget why this was done this way.
if post_type == 'url':
_thread.start_new_thread(os.system, ('python3 utilities/get_thumbnail.py %s "%s"' % (str(new_post.id), urllib.parse.quote(url)),))
#_thread.start_new_thread(os.system, ('python3 utilities/get_thumbnail.py %s "%s"' % (str(new_post.id), urllib.parse.quote(url)),))
thread = Thread(target = utilities.get_thumbnail.main, args=(str(new_post.id), url,))
thread.start()
thread.join()

new_post.permalink = new_post.sub + '/' + str(new_post.id) + '/' + new_post.inurl_title + '/'

Expand Down
Empty file removed app/languages.py
Empty file.
4 changes: 2 additions & 2 deletions app/templates/user/user.html
Expand Up @@ -44,10 +44,10 @@ <h6 class='user-profile-info-top'>/u/{{ vuser.username }}
{% endif %}

<div class='user-bio'>
<div style="display: inline-flex;">About:</div>
{% if vuser.bio == None %}
<div class='bio-text-wrap' style="opacity: 0.5;"><p class='bio-text'>This user has not set a bio.</p></div>
<!-- <div class='bio-text-wrap' style="opacity: 0.5;"><p class='bio-text'>This user has not set a bio.</p></div> -->
{% else %}
<div style="display: inline-flex;">About:</div>
<div class='bio-text-wrap'><p data-toggle='tootltip' title="{{ vuser.bio }}" class='bio-text'>{{ vuser.bio }}</p></div>
{% endif %}
</div>
Expand Down
11 changes: 6 additions & 5 deletions app/utilities/get_thumbnail.py
Expand Up @@ -31,16 +31,17 @@ def create_thumbnail(r, tid):
r = requests.post(config.URL + '/clear_cache', data={'key':config.API_OPER_KEY})
print(r.text)

def main():
c = False
tid = int(sys.argv[1])
url = urllib.parse.unquote(sys.argv[2])
def main(tid=None, url=None):
if tid is None:
tid = int(sys.argv[1])
if url is None:
url = urllib.parse.unquote(sys.argv[2])

r = requests.get(url, proxies=config.PROXIES, allow_redirects=True)

if r.headers['Content-Type'].split('/')[0] == 'image':
create_thumbnail(r, tid)
add_remote_image(url, tid)
c = True
else:
soup = BeautifulSoup(r.text)
image = soup.find('meta', property='og:image')
Expand Down

0 comments on commit f1e5bed

Please sign in to comment.