Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. TIMEFILENAME = "Chiffres.htm"
  3. COUNT = 125
  4. TIMEGAP = 7
  5.  
  6.  
  7. import twitter
  8.  
  9. api = twitter.Api(username = "gabs48", password = "")
  10. statuses = api.GetUserTimeline(user="be_rail",count=COUNT)
  11.  
  12. class date:
  13. "This class is developped to exploit a string date in 30 characters from twitter"
  14.  
  15.     monthtxt = ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  16.     monthl = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  17.     montht = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]
  18.    
  19.     day = 0
  20.     month = 0
  21.     year = 0
  22.     serie = 0
  23.     txt = ""
  24.    
  25.     def __init__ (self, texte):
  26.        
  27.         self.txt = texte
  28.         self.day = int(self.txt[8:10])
  29.         i = 0
  30.         while i < 12:
  31.             if self.monthtxt[i] == self.txt[4:7] :
  32.                 self.month = i + 1
  33.                 break;
  34.             i = i + 1
  35.         self.year = int(self.txt[26:30])
  36.         self.serie = self.day + self.montht[self.month - 1] + 365 * self.year
  37.            
  38.     def GetSerie (self):
  39.        
  40.         return self.serie
  41.        
  42.     def GetDay (self):
  43.        
  44.         return self.day
  45.  
  46.     def GetMonth (self):
  47.        
  48.         return self.month
  49.        
  50.     def GetYear (self):
  51.        
  52.         return self.year
  53.        
  54.        
  55.  
  56.  
  57. def TimeExploitation ( gap = TIMEGAP, nbre = COUNT, filedest = TIMEFILENAME):
  58.        
  59.         # fetch the date
  60.         i=0
  61.         liste = []
  62.  
  63.         while i < nbre:
  64.             liste.append ( date(statuses[i].GetCreatedAt()) )
  65.             i = i + 1
  66.            
  67.         # work out the number of points
  68.         liste.reverse()
  69.         nbrepoints = (liste[i-1].GetSerie() - liste[0].GetSerie())/gap
  70.         print nbrepoints
  71.        
  72.        
  73.         # write the text
  74.         ff = open (filedest, 'w')      
  75.         i=1
  76.         j=0
  77.         value = 0
  78.         prev = liste[0]
  79.         ff.write("Point\t\tDate\t\tValue")
  80.        
  81.         while i < nbre and j < nbrepoints :
  82.            
  83.             if liste[i].GetSerie() < prev.GetSerie() + gap:
  84.                 value = value + 1
  85.            
  86.             else :
  87.                 texte = "%(a)u\t\t %(b)u/%(c)u/%(d)u\t\t%(e)u\n" % \
  88.                     {'a': j, 'b': liste[i].GetDay(), 'c': liste[i].GetMonth(), 'd': liste[i].GetYear(), 'e': value}
  89.                 ff.write (texte)
  90.                 prev = liste[i]
  91.                 value = 0
  92.                 j = j + 1
  93.            
  94.             i = i + 1
  95.         ff.close()
  96.        
  97. TimeExploitation ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement