find.py 1.0 KB

12345678910111213141516171819202122232425
  1. import config
  2. from class_xml import XML
  3. def find_id():
  4. t = input('selectionnez\n\t1 : ratp\n\t2 : jcdecaux_vls (velib)\n')
  5. if int(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 int(t) == 2:
  10. print('Télechargement de la liste des stations...')
  11. xml = XML(url='https://api.jcdecaux.com/vls/v1/stations?contract=paris&apiKey=' + config.api_key['jcdecaux'], lang='json')
  12. 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
  13. else:
  14. raise ValueError('mauvaise réponsse !')
  15. while True:
  16. pat = input('Rechercher (ctrl+c pour quitter) : ').lower()
  17. print('Correspondances :')
  18. for key, value in dic.items():
  19. if pat in value.lower():
  20. print('id ' + key + ' : ' + value)
  21. find_id()