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

refactor main to use YAML parser and test with personal twitter bot #50

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

erikkristoferanderson
Copy link
Contributor

πŸ‘¨β€πŸ’» Changes proposed

factor main and load_env plus just print for now

We can't use tweepy.API, because the twitter bot
account is only allowed to use twitter API v2,
which is compatible with tweepy.Client().
Also the loadenv file needed to be refactored
because it wasn't working.
Also changed the logic in main.py to suit the
new reminders.txt format.
Also created an example .env-example file to
show the shape of what the .env files needs
to be, and added .env to .gitignore.

mentions #40

βœ”οΈ Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title of my pull request is a short description of the requested changes.

πŸ“„ Note to reviewers

We need a bearer-token to authenticate with the V2 Twitter API.

πŸ“· Screenshots

We can't use tweepy.API, because the twitter bot
account is only allowed to use twitter API v2,
which is compatible with tweepy.Client().
Also the loadenv file needed to be refactored
because it wasn't working.
Also changed the logic in main.py to suit the
new reminders.txt format.
Also created an example .env-example file to
show the shape of what the .env files needs
to be, and added .env to .gitignore.
@erikkristoferanderson
Copy link
Contributor Author

With bearer token, I attempted to run this, and the error was:
tweepy.errors.Forbidden: 403 Forbidden

main.py Outdated
# Select a random line from the reminders file.
lines = [line[1:] for line in lines if line[0] == "-"]
lines = [line[3:] for line in lines if len(line) > 2 and line[2] == "-"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there might be a better solution here.

Maybe check if the first non-whitespace character is the hyphen or not, and if it is, remove all the whitespaces around it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So strip the line of white space and then check if the first character is a hyphen? That would work. But I'm not sure what you mean by "remove all the whitespaces around it". Still, I'll try making an edit.

Alternately, would it be better to use Python's yaml parser?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it might be better to use Python's YAML parser!

@erikkristoferanderson
Copy link
Contributor Author

I will refactor this using the Python yaml parser.

@erikkristoferanderson
Copy link
Contributor Author

The bot does send tweets, with my personal bot credentials. See here:
https://twitter.com/odes_erik_bot/status/1528828488878284800

@erikkristoferanderson erikkristoferanderson changed the title refactor main and load_env plus just print for now refactor main to use YAML parser and test with personal twitter bot May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants