find.py 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. import config
  2. from class_xml import XML
  3. def find_id():
  4. t = int(input('selectionnez\n\t1 : ratp\n\t2 : transilien\n\t3 : jcdecaux_vls (velib)\n'))
  5. if t == 1:
  6. print('Télechargement de la liste des lignes...')
  7. xml = XML(url='http://www.ratp.fr/meteo/', lang='html')
  8. dic = {tag['id']: tag['id'].replace('_', ' ') for tag in xml.data.select('.encadre_ligne')}
  9. elif t == 2:
  10. print('Télechargement de la liste des lignes...')
  11. xml = XML(url='http://www.transilien.com/info-trafic/temps-reel', lang='html')
  12. dic = {}
  13. for line in xml.data.select('div.b_info_trafic')[0].find_all('div', recursive=False):
  14. id = line.select('.picto-transport')[1].get_text()
  15. dic[id] = id.replace('-', ' ')
  16. elif t == 3:
  17. print('Télechargement de la liste des stations...')
  18. xml = XML(url='https://api.jcdecaux.com/vls/v1/stations?contract=paris&apiKey=' + config.api_key['jcdecaux'], lang='json')
  19. dic = {sta.number.string: sta.find('name').string + ' (' + sta.address.string + ')' for sta in xml.data.find_all("item")} # we use find('name') because .name is the current tag name
  20. else:
  21. raise ValueError('mauvaise réponsse !')
  22. while True:
  23. pat = input('Rechercher (ctrl+c pour quitter) : ').lower()
  24. print('Correspondances :')
  25. for key, value in dic.items():
  26. if pat in value.lower():
  27. print('id ' + key + ' : ' + value)
  28. find_id()