Advertisement
Guest User

AKTermine.py

a guest
Mar 6th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.80 KB | None | 0 0
  1. #!/bin/python
  2. from BeautifulSoup import BeautifulSoup
  3. import urllib2
  4. import time
  5.  
  6. aschheim = 'http://www.autokinos-deutschland.de/programm/index-muenchen-aschheim.php?cPath=22'
  7. gravenbruch = 'http://www.autokinos-deutschland.de/programm/index-frankfurt-gravenbruch.php?cPath=24'
  8. essen = 'http://www.autokinos-deutschland.de/programm/indexessen.php?cPath=25'
  9. porz = 'http://www.autokinos-deutschland.de/programm/index-koeln-porz.php?cPath=26'
  10. kornwestheim = 'http://www.autokinos-deutschland.de/programm/index-stuttgart-kornwestheim.php?cPath=27'
  11.  
  12. alle_filme = [[0 for x in range(3)] for x in range(20)]
  13.  
  14. def unique_items(L):
  15.     found = set()
  16.     for item in L:
  17.         if item[0] not in found:
  18.             yield item
  19.             found.add(item[0])
  20.  
  21. def removeBlankRows(grid):
  22.     return [list(row) for row in grid if any(row)]
  23.  
  24. def getProgram(url):
  25.  
  26.     # 0 for x in range(cols_count) for x in range(rows_count)
  27.     filme = [[0 for x in range(3)] for x in range(20)]
  28.  
  29.     i=0
  30.     u=0
  31.     kino=""
  32.  
  33.     if url == aschheim:
  34.         kino = "[A]"
  35.     elif url == gravenbruch:
  36.         kino = "[G]"
  37.     elif url == essen:
  38.         kino = "[E]"
  39.     elif url == porz:
  40.         kino = "[P]"
  41.     elif url == kornwestheim:
  42.         kino = "[K]"
  43.  
  44.     response = urllib2.urlopen(url)
  45.     html = response.read()
  46.     soup = BeautifulSoup(html.decode('utf-8', 'ignore'), convertEntities=BeautifulSoup.HTML_ENTITIES)
  47.  
  48.     allg = soup.findAll("table", {"class" : "productListing"})
  49.     einzelnfilm = allg[0].findAll("td", {"class" : "productListing-data"})
  50.  
  51.     for rows in einzelnfilm:
  52.         startdatum = ""
  53.         titel = einzelnfilm[i+1].find("div",{"class" : "FilmHeading1"})
  54.         runtime_raw = einzelnfilm[i+1].findAll("tr")
  55.         runtime = runtime_raw[2].findAll("td",{"class" : "productDesc"})
  56.         filmtitel = titel.string.strip()
  57.         startdatum += runtime[0].string.strip() + " "
  58.         startdatum += runtime[1].string.strip()
  59.  
  60.         filme[u][0] = str(filmtitel)
  61.         filme[u][1] = str(startdatum[4:])
  62.         filme[u][2] = str(kino)
  63.  
  64.         i += 2
  65.         u += 1
  66.  
  67.         if i == len(einzelnfilm):
  68.             break
  69.  
  70.     return unique_items(filme)
  71.  
  72.  
  73. print ""
  74. print "Aktuelles Autokino Programm v0.1"
  75. print "[A] Aschheim"
  76. print "[G] Gravenbruch"
  77. print "[E] Essen"
  78. print "[P] Porz"
  79. print "[K] Kornwestheim"
  80. print ""
  81.  
  82. alle_filme += getProgram(aschheim)
  83. alle_filme += getProgram(gravenbruch)
  84. alle_filme += getProgram(essen)
  85. alle_filme += getProgram(porz)
  86. alle_filme += getProgram(kornwestheim)
  87.  
  88. alle_filme = removeBlankRows(alle_filme)
  89. alle_filme = sorted(alle_filme,key=lambda x:time.strptime(str(x[1]),"%d.%m."))
  90. alle_filme = unique_items(alle_filme)
  91.  
  92. v = 1
  93.  
  94. for row in alle_filme:
  95.     print str(str(v) + " - " + row[1] + " - " + row[0] + " - " + row[2])
  96.     v += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement