arnaucube
arnaucube/tuitviewerPublic Self-hosted repository
tuitviewer/tuitsview.py
tuitsview.pyRaw
 1# -*- coding: utf-8 -*-
 2
 3import sys
 4import tweepy
 5import os
 6import xml.etree.cElementTree as ET
 7
 8consumer_key = 'XXXXXXX'
 9consumer_secret = 'XXXXXXX'
10access_token = 'XXXXXXX'
11access_secret = 'XXXXXXX'
12
13
14auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
15auth.set_access_token(access_token, access_secret)
16
17
18api = tweepy.API(auth)
19
20#gets the last twits que veuria l'usuari al home
21##display homepage tweets of authenticated user
22for i in range(0, 5):
23    print(" ")
24print("...........---------/////////TL\\\\\\\\-------............")
25print(" ")
26
27root = ET.Element("root")
28llistatuits = ET.SubElement(root, "llistatuits")
29
30public_tweets = api.home_timeline(count=90)
31for tweet in reversed(public_tweets):
32    print("::::::::::::::::")
33    hora= tweet.created_at.strftime('%H')
34    hora= int(hora) + 1
35    emisor= tweet.user.name + " - @" + tweet.user.screen_name
36    print(emisor  + " -" + str(hora) + ":" + tweet.created_at.strftime('%M:%S'))
37    #continguttuit=tweet.text.encode('latin-1', 'ignore').decode('utf-8', 'ignore')
38    continguttuit=tweet.text.encode('latin-1', 'ignore').decode('utf-8', 'ignore')
39    print (continguttuit)
40    nretuits=str(tweet.retweet_count)
41    print (nretuits)
42    horatuit= str(hora) + ":" + tweet.created_at.strftime('%M:%S')
43    if 'media' in tweet.entities:
44        for image in  tweet.entities['media']:
45            imatgetuit= image['media_url']
46            ET.SubElement(llistatuits, "tuit", de=emisor, retuits=nretuits, hora=horatuit, imatge=imatgetuit).text = str(continguttuit)
47    else:
48        ET.SubElement(llistatuits, "tuit", de=emisor, retuits=nretuits, hora=horatuit).text = str(continguttuit)
49
50
51tree = ET.ElementTree(root)
52tree.write("dadestw.xml")
53
54print(" ")
55
56import webbrowser
57webbrowser.open_new('index.html')