You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

8 years ago
8 years ago
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import tweepy
  4. import os
  5. import xml.etree.cElementTree as ET
  6. consumer_key = 'XXXXXXX'
  7. consumer_secret = 'XXXXXXX'
  8. access_token = 'XXXXXXX'
  9. access_secret = 'XXXXXXX'
  10. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  11. auth.set_access_token(access_token, access_secret)
  12. api = tweepy.API(auth)
  13. #gets the last twits que veuria l'usuari al home
  14. ##display homepage tweets of authenticated user
  15. for i in range(0, 5):
  16. print(" ")
  17. print("...........---------/////////TL\\\\\\\\-------............")
  18. print(" ")
  19. root = ET.Element("root")
  20. llistatuits = ET.SubElement(root, "llistatuits")
  21. public_tweets = api.home_timeline(count=90)
  22. for tweet in reversed(public_tweets):
  23. print("::::::::::::::::")
  24. hora= tweet.created_at.strftime('%H')
  25. #horari d'estiu
  26. hora= int(hora) + 2
  27. emisor= tweet.user.name + " - @" + tweet.user.screen_name
  28. print(emisor + " -" + str(hora) + ":" + tweet.created_at.strftime('%M:%S'))
  29. #continguttuit=tweet.text.encode('latin-1', 'ignore').decode('utf-8', 'ignore')
  30. continguttuit=tweet.text.encode('latin-1', 'ignore').decode('utf-8', 'ignore')
  31. print (continguttuit)
  32. nretuits=str(tweet.retweet_count)
  33. print (nretuits)
  34. horatuit= str(hora) + ":" + tweet.created_at.strftime('%M:%S')
  35. if 'media' in tweet.entities:
  36. for image in tweet.entities['media']:
  37. imatgetuit= image['media_url']
  38. ET.SubElement(llistatuits, "tuit", de=emisor, retuits=nretuits, hora=horatuit, imatge=imatgetuit).text = str(continguttuit)
  39. else:
  40. ET.SubElement(llistatuits, "tuit", de=emisor, retuits=nretuits, hora=horatuit).text = str(continguttuit)
  41. tree = ET.ElementTree(root)
  42. tree.write("dadestw.xml")
  43. print(" ")
  44. #OPCIÓ QUE OBRE AUTOMÀTICAMENT UNA FINESTRA DEL NAVEGADOR PER VISUALITZAR ELS TWEETS
  45. #import webbrowser
  46. #webbrowser.open_new('index.html')