Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
VickiLanger opened this issue Oct 8, 2020 · 14 comments
Closed
Labels
enhancement New feature or request Hacktoberfest Requesting input/assistance from anyone help wanted Extra attention is needed

Comments

@VickiLanger
Copy link
Owner

VickiLanger commented Oct 8, 2020

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/

@VickiLanger VickiLanger added enhancement New feature or request help wanted Extra attention is needed Hacktoberfest Requesting input/assistance from anyone labels Oct 8, 2020
@VickiLanger VickiLanger changed the title Incorporate generateImagePost.py with tweet.py Incorporate generated images with tweet.py to actually tweet the images Oct 8, 2020
@Ares358
Copy link
Collaborator

Ares358 commented Oct 9, 2020

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
Copy link
Owner Author

@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
Copy link
Collaborator

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

@VickiLanger
Copy link
Owner Author

@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
Copy link
Collaborator

Ares358 commented Oct 14, 2020

@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
Copy link
Collaborator

@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
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link
Collaborator

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
Copy link
Owner Author

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
Copy link
Collaborator

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
Copy link
Owner Author

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

@VickiLanger
Copy link
Owner Author

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest Requesting input/assistance from anyone help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants