VickiLanger / LGBTQ-of-the-day-bot

Twitter bot tweeting fun goofy lgbtq things and queer history of the day
https://twitter.com/LGBTQotd
GNU General Public License v3.0
82 stars 173 forks source link

Incorporate generated images with tweet.py to actually tweet the images #90

Closed VickiLanger closed 3 years ago

VickiLanger commented 3 years ago

Issue #2 discussed generating images from text with the images in img_bg. Now that the images are generated with generateImagePost.py, they need to be able to be tweeted with tweet.py

https://iq.opengenus.org/post-image-twitter-api/

Ares358 commented 3 years ago

Is there any difference between the images named "{no}" and images named "{no}+a" ? Why don't they all have the same naming syntax?

VickiLanger commented 3 years ago

@Ares358 There is no difference. I took the easiest way I could think of when renaming them all at once. I should've named them all the same

JasirZaeem commented 3 years ago

I think this issue was resolved after PR #100 and can be closed now.

VickiLanger commented 3 years ago

@JasirZaeem The PR definitely addressed the issue. It's throwing an error though and I haven't had a chance to check it out.


2020-10-14T00:02:38.345206+00:00 app[scheduler.4247]: ModuleNotFoundError: No module named 'PIL'```
Ares358 commented 3 years ago

@JasirZaeem The PR definitely addressed the issue. It's throwing an error though and I haven't had a chance to check it out.

2020-10-14T00:02:38.345206+00:00 app[scheduler.4247]: ModuleNotFoundError: No module named 'PIL'```

Installing Python Image Library via the command pip install Pillow should solve it.

JasirZaeem commented 3 years ago

@JasirZaeem The PR definitely addressed the issue. It's throwing an error though and I haven't had a chance to check it out.


2020-10-14T00:02:38.345206+00:00 app[scheduler.4247]: ModuleNotFoundError: No module named 'PIL'```

PIL(pillow) is being used to write the tweets on images, the error says it's missing on the machine you tried running the bot on. Using pip install Pillow like @Ares358 suggested to install it should solve the issue.

VickiLanger commented 3 years ago

I update pil locally, but I don't run the bot from my computer. I run the bot using Heroku... Nevermind, I figured out how to add it with the console in Heroku. I'll leave the issue open until I see it work Screenshot of heroku console "2020-10-14T15:01:36.733155+00:00 app[scheduler.2109]: Traceback (most recent call last):
2020-10-14T15:01:36.733211+00:00 app[scheduler.2109]:   File "tweet.py", line 15, in <module>
2020-10-14T15:01:36.733325+00:00 app[scheduler.2109]:     from get_img_for_tweet import get_img_for_tweet
2020-10-14T15:01:36.733364+00:00 app[scheduler.2109]:   File "/app/get_img_for_tweet.py", line 11, in <module>
2020-10-14T15:01:36.733546+00:00 app[scheduler.2109]:     from PIL import Image, ImageDraw, ImageFont
2020-10-14T15:01:36.733592+00:00 app[scheduler.2109]: ModuleNotFoundError: No module named 'PIL'
2020-10-14T15:01:36.815969+00:00 heroku[scheduler.2109]: Process exited with status 1
2020-10-14T15:01:36.884799+00:00 heroku[scheduler.2109]: State changed from up to complete
2020-10-14T15:37:47.295494+00:00 app[api]: Starting process with command `python3 -m pip install --upgrade Pillow` by user vicki_langer@hotmail.com
2020-10-14T15:38:02.713399+00:00 heroku[run.4979]: State changed from starting to up
2020-10-14T15:38:03.467578+00:00 heroku[run.4979]: Awaiting client
2020-10-14T15:38:03.498718+00:00 heroku[run.4979]: Starting process with command `python3 -m pip install --upgrade Pillow`
2020-10-14T15:38:18.892137+00:00 heroku[run.4979]: Process exited with status 0
2020-10-14T15:38:18.936951+00:00 heroku[run.4979]: State changed from up to complete"

VickiLanger commented 3 years ago

Okay, so, it still didn't work. that clearly wasn't the way to do it. I think I just need to update requirements.txt

JasirZaeem commented 3 years ago

Yes that might be the way to do it, https://devcenter.heroku.com/articles/python-pip this says so at least. I have only used Linux vpses for experimenting with things so don't have any experience with Heroku.

VickiLanger commented 3 years ago

It was happy with my fix and now it's not happy again.


2020-10-15T00:02:01.850597+00:00 app[scheduler.4944]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 194, in __init__
2020-10-15T00:02:01.850748+00:00 app[scheduler.4944]:     font, size, index, encoding, layout_engine=layout_engine
JasirZaeem commented 3 years ago

I think the problem might be missing fonts, at this line https://github.com/JasirZaeem/LGBTQ-of-the-day-bot/blob/60288208a79fbc2280d9f3317136731f6ae945f1/get_img_for_tweet.py#L82 and the one after, arial.ttf is used, on windows where I and the contributor who originally added the code used it, this would work, but this probably fails on heroku.

You'll have to upload arial.ttf, or some other font file, yourself, to use it. I don't have experience with heroku but this might be helpful http://stackoverflow.com/questions/57794602/using-ttf-font-file-in-pillow-within-a-django-app-hosted-on-heroku

VickiLanger commented 3 years ago

Thank you so much @JasirZaeem. I had no clue you could link to a specific line. Neat.

VickiLanger commented 3 years ago

Well, it still doesn't like it.

font_type = ImageFont.truetype('/assets/Nunito-Regular.ttf', 40)
font_type2 = ImageFont.truetype('/assets/Nunito-Regular.ttf', 40*2)
2020-10-16T12:00:22.737878+00:00 app[scheduler.1478]:     font_type = ImageFont.truetype('/assets/Nunito-Regular.ttf', 40)
2020-10-16T12:00:22.737901+00:00 app[scheduler.1478]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 836, in truetype
2020-10-16T12:00:22.738235+00:00 app[scheduler.1478]:     return freetype(font)
2020-10-16T12:00:22.738236+00:00 app[scheduler.1478]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 833, in freetype
2020-10-16T12:00:22.738581+00:00 app[scheduler.1478]:     return FreeTypeFont(font, size, index, encoding, layout_engine)
2020-10-16T12:00:22.738582+00:00 app[scheduler.1478]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 194, in __init__
2020-10-16T12:00:22.738752+00:00 app[scheduler.1478]:     font, size, index, encoding, layout_engine=layout_engine
2020-10-16T12:00:22.738756+00:00 app[scheduler.1478]: OSError: cannot open resource

Gonna try using PIL.ImageFont.load_default() to see if that temporarily fixes it (reference) (another reference).

VickiLanger commented 3 years ago

Okay, Images work. I'm gonna open a new issue for the font and work on that. Thank you both so much for your work and for helping me figure out the errors.

https://twitter.com/LgbtQotd/status/1317118324124299264?s=20