logo

scripts

A bunch of scripts, some to be moved to their own repository git clone https://hacktivis.me/git/scripts.git

stream.py (1958B)


  1. #!/usr/bin/python3
  2. # -*- encoding: utf-8 -*-
  3. import html, sys
  4. import config
  5. #o = TwitterOAuth.read_file('credentials.txt')
  6. #api = TwitterAPI(
  7. # o.consumer_key,
  8. # o.consumer_secret,
  9. # o.access_token_key,
  10. # o.access_token_secret)
  11. def main(user):
  12. import common
  13. api = common.api(config.credentials['consumer_key'], config.credentials['consumer_secret'], user['access_token_key'], user['access_token_secret'])
  14. r = api.request('user', {'replies': 'all'})
  15. for item in r:
  16. if 'text' in item:
  17. print(common.f['tweet'] % {'id': item['id'], 'screen_name': item['user']['screen_name'], 'name': item['user']['name'], 'text': html.unescape(item['text'])})
  18. elif 'friends' in item:
  19. print(common.friend_list_garbage)
  20. elif 'event' in item:
  21. try:
  22. if item['event'] in ('favorite', 'favorited_retweet'):
  23. print(common.f['favorite'] % { item['source']['screen_name'], item['event'], item['target_object']['user']['screen_name'], item['target_object']['text']})
  24. elif item['event'] in ('retweet', 'retweeted_retweet'):
  25. print(common.f['retweet'] % { item['source']['screen_name'], item['event'], item['target_object']['user']['screen_name'], item['target_object']['text']})
  26. elif item['event'] == 'follow':
  27. print(common.f['follow'] % { item['source']['screen_name'], item['event'], item['target']['user']['screen_name']})
  28. else:
  29. print(common.f['default'] % { item['source']['screen_name'], item['event'], item['target_object']['user']['screen_name'], item['target_object']['text']})
  30. except:
  31. print(item)
  32. print(sys.exc_info())
  33. else:
  34. print(item)
  35. user = dict()
  36. username = list(config.credentials['users'])[0]
  37. #if __name__ == "__main__":
  38. # try:
  39. # username = sys.argv[0]
  40. # except KeyError:
  41. # print('Protip: you can specify an user account, anyway using first account')
  42. # username = list(config.credentials['users'])[0]
  43. user = config.credentials['users'][username]
  44. user['name'] = username
  45. username = None
  46. main(user)