Skip to content

Instantly share code, notes, and snippets.

@giordano91
Created January 12, 2017 20:47
Show Gist options
  • Save giordano91/c4826a1088c6ee533035c606be302b44 to your computer and use it in GitHub Desktop.
Save giordano91/c4826a1088c6ee533035c606be302b44 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.4.2 (/usr/bin/python3.4)" project-jdk-type="Python SDK" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/twitter_scripts.iml" filepath="$PROJECT_DIR$/.idea/twitter_scripts.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
A Python 3.X script to get the most popular two hashtags from specific user.
Return a list.
"""
import tweepy
from tweepy import OAuthHandler, StreamListener
class StdOutListener(StreamListener):
def on_data(self, data):
print(data)
return True
def on_error(self, status):
print(status)
if __name__ == '__main__':
consumer_key = 'ZS4wSwoFDHz5CB3IEi2NNDRDp'
consumer_secret = 'hPL7sGIv5uSznND9YupYazJFOQz0y0Yvsc0G5RIKQiWDXLUJdP'
access_token = '4860695419-d2IFyVALoAaVteDZDfFn6EtMzyrA85I01IGxIEk'
access_token_secret = '6lrDnCDISPMH0mS2Lt9f4vdohcZa0gKgldtk2rv3hnzA3'
hashtags_dict = {}
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweets = api.user_timeline(screen_name='GiordanoS91', count=200)
for tweet in tweets:
hashtags = tweet.entities.get('hashtags')
for hashtag in hashtags:
if hashtag['text'] in hashtags_dict.keys():
hashtags_dict[hashtag['text']] += 1
else:
hashtags_dict[hashtag['text']] = 1
print(sorted(hashtags_dict, key=hashtags_dict.get, reverse=True)[:2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment