Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- TIMEFILENAME = "Chiffres.htm"
- COUNT = 125
- TIMEGAP = 7
- import twitter
- api = twitter.Api(username = "gabs48", password = "")
- statuses = api.GetUserTimeline(user="be_rail",count=COUNT)
- class date:
- "This class is developped to exploit a string date in 30 characters from twitter"
- monthtxt = ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
- monthl = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
- montht = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
- day = 0
- month = 0
- year = 0
- serie = 0
- txt = ""
- def __init__ (self, texte):
- self.txt = texte
- self.day = int(self.txt[8:10])
- i = 0
- while i < 12:
- if self.monthtxt[i] == self.txt[4:7] :
- self.month = i + 1
- break;
- i = i + 1
- self.year = int(self.txt[26:30])
- self.serie = self.day + self.montht[self.month - 1] + 365 * self.year
- def GetSerie (self):
- return self.serie
- def GetDay (self):
- return self.day
- def GetMonth (self):
- return self.month
- def GetYear (self):
- return self.year
- def TimeExploitation ( gap = TIMEGAP, nbre = COUNT, filedest = TIMEFILENAME):
- # fetch the date
- i=0
- liste = []
- while i < nbre:
- liste.append ( date(statuses[i].GetCreatedAt()) )
- i = i + 1
- # work out the number of points
- liste.reverse()
- nbrepoints = (liste[i-1].GetSerie() - liste[0].GetSerie())/gap
- print nbrepoints
- # write the text
- ff = open (filedest, 'w')
- i=1
- j=0
- value = 0
- prev = liste[0]
- ff.write("Point\t\tDate\t\tValue")
- while i < nbre and j < nbrepoints :
- if liste[i].GetSerie() < prev.GetSerie() + gap:
- value = value + 1
- else :
- texte = "%(a)u\t\t %(b)u/%(c)u/%(d)u\t\t%(e)u\n" % \
- {'a': j, 'b': liste[i].GetDay(), 'c': liste[i].GetMonth(), 'd': liste[i].GetYear(), 'e': value}
- ff.write (texte)
- prev = liste[i]
- value = 0
- j = j + 1
- i = i + 1
- ff.close()
- TimeExploitation ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement