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

Code refactored to work in python3.6 #16

Merged
merged 1 commit into from
Aug 15, 2017

Conversation

ediamondscience
Copy link
Contributor

@ediamondscience ediamondscience commented Jul 3, 2017

As discussed in #15. I've tested tweeting, viewing trending hashtags, and viewing my timeline, but I haven't gone through all of the other features to make sure they aren't inexplicably broken. I'd suggest keeping the old master as a legacy branch just in case.

@CruiseDevice
Copy link
Owner

CruiseDevice commented Jul 4, 2017

Does this work on your machine? Have you checked it properly? When i try to run it on my machine, i get error when tried to get tweets of any user.

(venv) ➜ tweet_cli_test python3 tweet_cli.py Enter 'twweet' or 'get' or 'edit': get 1.Get tweets of any user 2.Get tweets of particular hashtag 3.Get trending topics 4.Read your timeline 5.Get your followers list 6.Get your tweets1 Enter the username whose twweet's you want to grab CruiseDevice getting tweets before 826797744765403135 ...%s tweets downloaded so far getting tweets before 788070751538667521 ...%s tweets downloaded so far Traceback (most recent call last): File "tweet_cli.py", line 185, in <module> main() File "tweet_cli.py", line 170, in main get_all_tweets(input('Enter the username whose twweet\'s you want to grab ')) File "tweet_cli.py", line 58, in get_all_tweets writer.writerow(["id","created_at","text"]) TypeError: a bytes-like object is required, not 'str'
Option 2 (Get tweets of particular hashtag) doesn't seem to work either.

(venv) ➜ tweet_cli_test python3 tweet_cli.py Enter 'twweet' or 'get' or 'edit': get 1.Get tweets of any user 2.Get tweets of particular hashtag 3.Get trending topics 4.Read your timeline 5.Get your followers list 6.Get your tweets2 Enter the hashtag : #100DaysOfCode Please be patient while we download the tweets We have got 200 tweets so far We have got 400 tweets so far We have got 600 tweets so far We have got 800 tweets so far We have got 1000 tweets so far Traceback (most recent call last): File "tweet_cli.py", line 185, in <module> main() File "tweet_cli.py", line 172, in main get_tweets_of_hashtag(input('Enter the hashtag : ')) File "tweet_cli.py", line 103, in get_tweets_of_hashtag writer.writerow([tweet]) TypeError: a bytes-like object is required, not 'str' (venv) ➜ tweet_cli_test
Please check it and the send PR.

@ediamondscience
Copy link
Contributor Author

I've solved the issue with the hashtag search that you pointed out, but I've encountered a new one. Tweepy is giving me a 429, so we need to do some math to figure out how to limit the number of requests that we're sending to the Twitter API to a reasonable number. I may open up a new issue if a solution doesn't become totally apparent with a little searching through the API documentation.

@ediamondscience
Copy link
Contributor Author

I think all issues above have been solved and the rate limiting has been implemented. The fixed version is #17.

@CruiseDevice
Copy link
Owner

I checked your PR. It does not seem to be working on my machine. I get error while getting the twitter data. The options are printing twice and i get error when i select one of the options. May be i am not executing the file as it should be executed. I am doing python3 twweet-cli.py. I will provide the error log below. Please check it

error log

tweet-cli-error

@ediamondscience
Copy link
Contributor Author

ediamondscience commented Jul 6, 2017

You'll need to hard code your account credentials into cfg at the top of twweet-cli.py to get this to work, status code 400 means bad authorization. I figured that we weren't going to rely on the SQL db to provide credentials anymore as discussed in #13 so I commented out that part of the code. Sorry, that was kind of my bad for not mentioning it in the pull request or my last comment.

I know that the feature worked because I generated #100DaysofCode.csv and CruiseDeviceTweets.csv with it, here's the tests I did on the broken features:

Getting hashtags:
working

Getting A User's tweets:
userpullworking

@0x006E
Copy link
Contributor

0x006E commented Aug 6, 2017

I think it would be good if it this is maintained as a new branch. Like one branchfor python 2.7 and one for python 3.6

@ediamondscience
Copy link
Contributor Author

Yeah, I think you're right. Sorry I haven't updated this in a while, things got away from me with my other projects. I'm currently working on a upgrade for this branch that allows details different accounts to be stored in a JSON file which I hope to upgrade to a pkl file using the pickle package for python for encryption so that account details aren't stored in plain text in a file. I'll close these pull requests once it's finished and open a new one.
If @CruiseDevice is willing to make a branch for me to merge with I would be more than happy to open a pull request with that version of this program on the new branch.

@0x006E
Copy link
Contributor

0x006E commented Aug 7, 2017

But your code has to be made to python 2.7 as both versions are released. And it should also be released in PyPi

@ediamondscience
Copy link
Contributor Author

It should be relatively easy to migrate between the two different versions, really just a matter of changing most input() calls to raw_input() calls.

I can't say I've ever done python packaging before so trying to get it released in PyPi would be pretty new for me.

@0x006E
Copy link
Contributor

0x006E commented Aug 7, 2017

The code is not just about input but there is syntax changes in python 3.6

@0x006E 0x006E mentioned this pull request Aug 8, 2017
@ediamondscience
Copy link
Contributor Author

Actually the way I refactored things, the only change should be the inputs. I over parenthized some print statements and added some .format calls that will work in both python 2.7 and python 3.6 to minimize the effort of going back and forth in the future. There really weren't any other compiling issues.

@CruiseDevice
Copy link
Owner

@ediamondscience Please update your fork with the master fork and send the pr to the new branch python-3.6. Before sending the pr verify all the functionalities are working, so the project should not break. Last time i didn't merge your pr because it was printing the options two times where it must print the option one time (you can refer the screenshots above). Even some of the options were not working, i don't know the exact reasons behind it.

@ediamondscience
Copy link
Contributor Author

@CruiseDevice I've got a version that I've maintained for some time on my fork, under the json+multiaccount branch. It's got a drastically different method for credential input, making it somewhat easier to get many sets of credentials entered at once. It has the user enter their credentials through a 4 line text file in an input directory for each account. It then reads those files once the program starts and builds a json file that contains the credentials for every account while checking for duplicate accounts. I'd be more than happy to create a pull request with the new branch here for that code if you'd like, but I don't think I'll be porting the current master branch over to python3.6 again as I really don't see what good that would do anyone considering how obsolete it would feel compared to my current branch. Have a look at that one and let me know what you want me to do.

For the last pull request, I checked and made sure that all the functions worked the same as they did for the python2.7 build. If things crashed for you it might be down to having issues going between the two versions of python, or not having your credentials in the right place (your code 400 error).

As for the UI duplication issues that you're referencing, they were a part of your code at the time, I just didn't bother to fix them because I wasn't here to work on UI, I was here to port the program to a newer version of python and add features to make it easier to use. It ended up being an extra main() call as I remember from fixing it on my latest branch.

@0x006E
Copy link
Contributor

0x006E commented Aug 13, 2017

I think you removd the edit option from the program in ur fork. Y that change I didn't understand. Edit is needed ryt???. Or we wud have to edit the directly. Please check that in that branch json+multiaccount

@ediamondscience
Copy link
Contributor Author

Yes, as I previously stated in this comment thread I replaced it with something I found infinitely easier to use. Instead of having a user manually type out their keys, it was easier to copy and paste into a text file and place it into an /input/ directory within the same directory as twweet-cli. The directory is checked each time the program is run and any text files that don't already have an entry in the accts.json file that the program generates are added in. Pretty sure that's all in the initaccs() function definition. There is also a set of instructions that display when you try running it for the first time or when you get bad authorization errors that explains all this as well. Have you tried running the program from my branch?

Copy link
Contributor

@0x006E 0x006E left a comment

Choose a reason for hiding this comment

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

Please make changes as per the comments and update this according to the master branch

@@ -47,7 +47,7 @@ def get_all_tweets(screen_name):
# update the id of the oldest tweet less one
oldest = alltweets[-1].id - 1

print "...%s tweets downloaded so far"%(len(alltweets))
print("...%s tweets downloaded so far".format(len(alltweets)))
Copy link
Contributor

Choose a reason for hiding this comment

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

print("...%s tweets downloaded so far".format(len(alltweets))) --> print("... {} tweets downloaded so far".format(len(alltweets)))

Copy link
Contributor

Choose a reason for hiding this comment

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

And in line 99, with open('%s.csv'%hash_tag, 'wb') as f: --> with open('%s.csv'%hash_tag, 'w') as f:

And in line 56, with open('%s_tweets.csv' % screen_name,'wb') as f: --> with open('%s_tweets.csv' % screen_name,'w') as f:

@ediamondscience
Copy link
Contributor Author

@nithinswarrier See #17, this is an older pull request than that one and it has the updated code.

@CruiseDevice CruiseDevice merged commit bddca7f into CruiseDevice:master Aug 15, 2017
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.

None yet

3 participants