import requests, pandas as pd, numpy as np, json
from requests import session
from bs4 import BeautifulSoup
url='http://osm-subway.maps.me/'
response = requests.get(url)
soup = BeautifulSoup(response.content)
links=[i['href'] for i in soup.findAll('a')[1:-3]]
systems={}
for link in links:
response = requests.get(url+link)
soup = BeautifulSoup(response.content)
print(link)
names=[' '.join(i.text.split(' ')[:-2]) for i in soup.find_all('td',{'class':'bold'})]
ids=[i['href'].split('.yaml')[0] for i in soup.findAll('a',{'class':'hlink'})[::2]]
for i in range(len(names)):
systems[ids[i]]=names[i]
algeria.html egypt.html ethiopia.html mauritius.html nigeria.html south-africa.html tunisia.html argentina.html brazil.html canada.html chile.html colombia.html dominican-republic.html mexico.html panama.html peru.html usa.html venezuela.html armenia.html azerbaijan.html china.html india.html indonesia.html iran.html japan.html kazakhstan.html malaysia.html north-korea.html philippines.html qatar.html saudi-arabia.html singapore.html south-korea.html taiwan.html thailand.html united-arab-emirates.html uzbekistan.html australia.html austria.html belarus.html belgium.html bulgaria.html czech-republic.html denmark.html estonia.html finland.html france.html georgia.html germany.html greece.html hungary.html ireland.html italy.html netherlands.html norway.html poland.html portugal.html romania.html russia.html spain.html sweden.html switzerland.html turkey.html uk.html ukraine.html
metros=json.loads(open('metrosy.json','r').read())
metrokeys={i.split('/')[-2]:i for i in metros.keys()}
for metro in metros:
metros[metro]['lr']=[]
for s in systems:
#s=s.replace('_','-')
if s in metrokeys:
metros[metrokeys[s]]['lr'].append({'name':systems[s],'id':s})
print(s,'appended to',metrokeys[s])
elif s.split('_-_')[0] in metrokeys:
metros[metrokeys[s.split('_-_')[0]]]['lr'].append({'name':systems[s],'id':s})
print(s,'appended to',metrokeys[s.split('_-_')[0]])
elif s.split('_')[0] in metrokeys:
metros[metrokeys[s.split('_')[0]]]['lr'].append({'name':systems[s],'id':s})
print(s,'appended to',metrokeys[s.split('_')[0]])
elif s.replace('_','-') in metrokeys:
metros[metrokeys[s.replace('_','-')]]['lr'].append({'name':systems[s],'id':s})
print(s,'appended to',metrokeys[s.replace('_','-')])
elif s.split('_-_')[0].replace('_','-') in metrokeys:
metros[metrokeys[s.split('_-_')[0].replace('_','-')]]['lr'].append({'name':systems[s],'id':s})
print(s,'appended to',metrokeys[s.split('_-_')[0].replace('_','-')])
else:
print('ERROR',s)
algiers appended to https://www.metrolinemap.com/metro/algiers/ cairo appended to https://www.metrolinemap.com/metro/cairo/ ERROR addis_ababa ERROR mauritius ERROR abuja ERROR cape_town ERROR durban ERROR eastern_cape ERROR johannesburg_-_gautrain ERROR johannesburg_-_metrorail ERROR tunis buenos_aires appended to https://www.metrolinemap.com/metro/buenos-aires/ ERROR mendoza ERROR baixada_santista belo_horizonte appended to https://www.metrolinemap.com/metro/belo-horizonte/ ERROR braslia ERROR fortaleza ERROR macei ERROR natal porto_alegre appended to https://www.metrolinemap.com/metro/porto-alegre/ recife appended to https://www.metrolinemap.com/metro/recife/ rio_de_janeiro appended to https://www.metrolinemap.com/metro/rio-de-janeiro/ rio_de_janeiro_-_supervia appended to https://www.metrolinemap.com/metro/rio-de-janeiro/ salvador appended to https://www.metrolinemap.com/metro/salvador/ ERROR so_paulo ERROR so_paulo_-_cptm ERROR calgary ERROR edmonton montreal appended to https://www.metrolinemap.com/metro/montreal/ ERROR ottawa toronto appended to https://www.metrolinemap.com/metro/toronto/ vancouver appended to https://www.metrolinemap.com/metro/vancouver/ santiago appended to https://www.metrolinemap.com/metro/santiago/ ERROR medelln santo_domingo appended to https://www.metrolinemap.com/metro/santo-domingo/ ERROR guadalajara mexico_city appended to https://www.metrolinemap.com/metro/mexico-city/ monterrey appended to https://www.metrolinemap.com/metro/monterrey/ panama_city appended to https://www.metrolinemap.com/metro/panama-city/ lima appended to https://www.metrolinemap.com/metro/lima/ atlanta appended to https://www.metrolinemap.com/metro/atlanta/ baltimore appended to https://www.metrolinemap.com/metro/baltimore/ boston appended to https://www.metrolinemap.com/metro/boston/ ERROR charlotte chicago appended to https://www.metrolinemap.com/metro/chicago/ cleveland appended to https://www.metrolinemap.com/metro/cleveland/ ERROR denver ERROR las_vegas los_angeles appended to https://www.metrolinemap.com/metro/los-angeles/ miami appended to https://www.metrolinemap.com/metro/miami/ ERROR minneapolis-st_paul ERROR new_york_-_jfk_airport new_york_city appended to https://www.metrolinemap.com/metro/new-york-city/ new_york_city_-_new_jersey appended to https://www.metrolinemap.com/metro/new-york-city/ new_york_city_-_path appended to https://www.metrolinemap.com/metro/new-york-city/ new_york_city_-_staten_island appended to https://www.metrolinemap.com/metro/new-york-city/ ERROR newark ERROR norfolk philadelphia appended to https://www.metrolinemap.com/metro/philadelphia/ philadelphia_-_patco appended to https://www.metrolinemap.com/metro/philadelphia/ philadelphia_-_snjrg appended to https://www.metrolinemap.com/metro/philadelphia/ ERROR sacramento ERROR san_diego san_francisco appended to https://www.metrolinemap.com/metro/san-francisco/ ERROR san_jos-santa_clara ERROR san_juan_puerto_rico washington_dc appended to https://www.metrolinemap.com/metro/washington/ caracas appended to https://www.metrolinemap.com/metro/caracas/ ERROR maracaibo ERROR valencia_carabobo yerevan appended to https://www.metrolinemap.com/metro/yerevan/ baku appended to https://www.metrolinemap.com/metro/baku/ beijing appended to https://www.metrolinemap.com/metro/beijing/ changchun appended to https://www.metrolinemap.com/metro/changchun/ changsha appended to https://www.metrolinemap.com/metro/changsha/ ERROR changzhou chengdu appended to https://www.metrolinemap.com/metro/chengdu/ chongqing appended to https://www.metrolinemap.com/metro/chongqing/ dalian appended to https://www.metrolinemap.com/metro/dalian/ dongguan appended to https://www.metrolinemap.com/metro/dongguan/ fuzhou appended to https://www.metrolinemap.com/metro/fuzhou/ guangzhou appended to https://www.metrolinemap.com/metro/guangzhou/ guiyang appended to https://www.metrolinemap.com/metro/guiyang/ hangzhou appended to https://www.metrolinemap.com/metro/hangzhou/ harbin appended to https://www.metrolinemap.com/metro/harbin/ hefei appended to https://www.metrolinemap.com/metro/hefei/ ERROR hohhot hong_kong appended to https://www.metrolinemap.com/metro/hong-kong/ jinan appended to https://www.metrolinemap.com/metro/jinan/ kunming appended to https://www.metrolinemap.com/metro/kunming/ ERROR lanzhou ERROR macau nanchang appended to https://www.metrolinemap.com/metro/nanchang/ nanjing appended to https://www.metrolinemap.com/metro/nanjing/ nanning appended to https://www.metrolinemap.com/metro/nanning/ ningbo appended to https://www.metrolinemap.com/metro/ningbo/ qingdao appended to https://www.metrolinemap.com/metro/qingdao/ shanghai appended to https://www.metrolinemap.com/metro/shanghai/ shanghai_-_s-train appended to https://www.metrolinemap.com/metro/shanghai/ shenyang appended to https://www.metrolinemap.com/metro/shenyang/ shenzhen appended to https://www.metrolinemap.com/metro/shenzhen/ shijiazhuang appended to https://www.metrolinemap.com/metro/shijiazhuang/ suzhou appended to https://www.metrolinemap.com/metro/suzhou/ tianjin appended to https://www.metrolinemap.com/metro/tianjin/ wenzhou appended to https://www.metrolinemap.com/metro/wenzhou/ wuhan appended to https://www.metrolinemap.com/metro/wuhan/ wuxi appended to https://www.metrolinemap.com/metro/wuxi/ xian appended to https://www.metrolinemap.com/metro/xian/ xiamen appended to https://www.metrolinemap.com/metro/xiamen/ ERROR xuzhou zhengzhou appended to https://www.metrolinemap.com/metro/zhengzhou/ ERROR rmqi ahmedabad appended to https://www.metrolinemap.com/metro/ahmedabad/ bangalore appended to https://www.metrolinemap.com/metro/bangalore/ chennai appended to https://www.metrolinemap.com/metro/chennai/ delhi appended to https://www.metrolinemap.com/metro/delhi/ hyderabad appended to https://www.metrolinemap.com/metro/hyderabad/ jaipur appended to https://www.metrolinemap.com/metro/jaipur/ kochi appended to https://www.metrolinemap.com/metro/kochi/ kolkata appended to https://www.metrolinemap.com/metro/kolkata/ lucknow appended to https://www.metrolinemap.com/metro/lucknow/ mumbai appended to https://www.metrolinemap.com/metro/mumbai/ nagpur appended to https://www.metrolinemap.com/metro/nagpur/ noida appended to https://www.metrolinemap.com/metro/noida/ jakarta appended to https://www.metrolinemap.com/metro/jakarta/ jakarta_lrt appended to https://www.metrolinemap.com/metro/jakarta/ ERROR palembang isfahan appended to https://www.metrolinemap.com/metro/isfahan/ mashhad appended to https://www.metrolinemap.com/metro/mashhad/ shiraz appended to https://www.metrolinemap.com/metro/shiraz/ tabriz appended to https://www.metrolinemap.com/metro/tabriz/ tehran appended to https://www.metrolinemap.com/metro/tehran/ ERROR chiba ERROR chiba_-_toyo ERROR chiba_-_yukarigaoka fukuoka appended to https://www.metrolinemap.com/metro/fukuoka/ hiroshima appended to https://www.metrolinemap.com/metro/hiroshima/ ERROR kamakura-enoshima ERROR kanazawa ERROR kitakyushu kobe appended to https://www.metrolinemap.com/metro/kobe/ kobe_new_transit appended to https://www.metrolinemap.com/metro/kobe/ kyoto appended to https://www.metrolinemap.com/metro/kyoto/ ERROR matsuyama nagoya appended to https://www.metrolinemap.com/metro/nagoya/ ERROR okinawa osaka appended to https://www.metrolinemap.com/metro/osaka/ osaka_-_rapit appended to https://www.metrolinemap.com/metro/osaka/ ERROR saitama ERROR saitama_-_ina sapporo appended to https://www.metrolinemap.com/metro/sapporo/ sendai appended to https://www.metrolinemap.com/metro/sendai/ tokyo appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_haneda_monorail appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_nippori-toneri_liner appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_rinkai appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_skyliner appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_tama_monorail appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_toei appended to https://www.metrolinemap.com/metro/tokyo/ tokyo_-_yurikamome appended to https://www.metrolinemap.com/metro/tokyo/ yokohama appended to https://www.metrolinemap.com/metro/yokohama/ yokohama_-_denentoshi appended to https://www.metrolinemap.com/metro/yokohama/ yokohama_-_minatomirai appended to https://www.metrolinemap.com/metro/yokohama/ almaty appended to https://www.metrolinemap.com/metro/almaty/ kuala_lumpur appended to https://www.metrolinemap.com/metro/kuala-lumpur/ pyongyang appended to https://www.metrolinemap.com/metro/pyongyang/ manila appended to https://www.metrolinemap.com/metro/manila/ doha appended to https://www.metrolinemap.com/metro/doha/ mecca appended to https://www.metrolinemap.com/metro/mecca/ singapore appended to https://www.metrolinemap.com/metro/singapore/ busan appended to https://www.metrolinemap.com/metro/busan/ daegu appended to https://www.metrolinemap.com/metro/daegu/ daejeon appended to https://www.metrolinemap.com/metro/daejeon/ gwangju appended to https://www.metrolinemap.com/metro/gwangju/ ERROR incheon ERROR incheon_-_airport seoul appended to https://www.metrolinemap.com/metro/seoul/ seoul_-_neotrans appended to https://www.metrolinemap.com/metro/seoul/ kaohsiung appended to https://www.metrolinemap.com/metro/kaohsiung/ taipei appended to https://www.metrolinemap.com/metro/taipei/ taoyuan appended to https://www.metrolinemap.com/metro/taoyuan/ bangkok appended to https://www.metrolinemap.com/metro/bangkok/ bangkok_-_airport appended to https://www.metrolinemap.com/metro/bangkok/ bangkok_-_skytrain appended to https://www.metrolinemap.com/metro/bangkok/ dubai appended to https://www.metrolinemap.com/metro/dubai/ tashkent appended to https://www.metrolinemap.com/metro/tashkent/ ERROR canberra sydney appended to https://www.metrolinemap.com/metro/sydney/ vienna appended to https://www.metrolinemap.com/metro/vienna/ vienna_s-bahn appended to https://www.metrolinemap.com/metro/vienna/ minsk appended to https://www.metrolinemap.com/metro/minsk/ brussels appended to https://www.metrolinemap.com/metro/brussels/ sofia appended to https://www.metrolinemap.com/metro/sofia/ prague appended to https://www.metrolinemap.com/metro/prague/ copenhagen appended to https://www.metrolinemap.com/metro/copenhagen/ ERROR tallinn helsinki appended to https://www.metrolinemap.com/metro/helsinki/ lille appended to https://www.metrolinemap.com/metro/lille/ lyon appended to https://www.metrolinemap.com/metro/lyon/ marseille appended to https://www.metrolinemap.com/metro/marseille/ paris appended to https://www.metrolinemap.com/metro/paris/ paris_rer appended to https://www.metrolinemap.com/metro/paris/ rennes appended to https://www.metrolinemap.com/metro/rennes/ toulouse appended to https://www.metrolinemap.com/metro/toulouse/ tbilisi appended to https://www.metrolinemap.com/metro/tbilisi/ berlin appended to https://www.metrolinemap.com/metro/berlin/ berlin_s-bahn appended to https://www.metrolinemap.com/metro/berlin/ ERROR bremen_s-bahn ERROR dresden_s-bahn hamburg appended to https://www.metrolinemap.com/metro/hamburg/ hamburg_s-bahn appended to https://www.metrolinemap.com/metro/hamburg/ ERROR hannover_s-bahn ERROR leipzig_s-bahn ERROR magdeburg_s-bahn munich appended to https://www.metrolinemap.com/metro/munich/ munich_s-bahn appended to https://www.metrolinemap.com/metro/munich/ nuremberg appended to https://www.metrolinemap.com/metro/nuremberg/ nuremberg_s-bahn appended to https://www.metrolinemap.com/metro/nuremberg/ ERROR rhein-ruhr ERROR stuttgart_s-bahn athens appended to https://www.metrolinemap.com/metro/athens/ budapest appended to https://www.metrolinemap.com/metro/budapest/ budapest_hev appended to https://www.metrolinemap.com/metro/budapest/ ERROR dublin brescia appended to https://www.metrolinemap.com/metro/brescia/ catania appended to https://www.metrolinemap.com/metro/catania/ genoa appended to https://www.metrolinemap.com/metro/genoa/ milan appended to https://www.metrolinemap.com/metro/milan/ naples appended to https://www.metrolinemap.com/metro/naples/ naples_-_aversa appended to https://www.metrolinemap.com/metro/naples/ rome appended to https://www.metrolinemap.com/metro/rome/ rome_-_leonardo_express appended to https://www.metrolinemap.com/metro/rome/ turin appended to https://www.metrolinemap.com/metro/turin/ amsterdam appended to https://www.metrolinemap.com/metro/amsterdam/ rotterdam appended to https://www.metrolinemap.com/metro/rotterdam/ oslo appended to https://www.metrolinemap.com/metro/oslo/ warsaw appended to https://www.metrolinemap.com/metro/warsaw/ lisbon appended to https://www.metrolinemap.com/metro/lisbon/ ERROR porto bucharest appended to https://www.metrolinemap.com/metro/bucharest/ kazan appended to https://www.metrolinemap.com/metro/kazan/ moscow appended to https://www.metrolinemap.com/metro/moscow/ moscow_-_aeroexpress appended to https://www.metrolinemap.com/metro/moscow/ nizhny_novgorod appended to https://www.metrolinemap.com/metro/nizhny-novgorod/ novosibirsk appended to https://www.metrolinemap.com/metro/novosibirsk/ saint_petersburg appended to https://www.metrolinemap.com/metro/saint-petersburg/ samara appended to https://www.metrolinemap.com/metro/samara/ ERROR volgograd yekaterinburg appended to https://www.metrolinemap.com/metro/yekaterinburg/ barcelona appended to https://www.metrolinemap.com/metro/barcelona/ bilbao appended to https://www.metrolinemap.com/metro/bilbao/ madrid appended to https://www.metrolinemap.com/metro/madrid/ ERROR mlaga ERROR palma ERROR seville ERROR valencia stockholm appended to https://www.metrolinemap.com/metro/stockholm/ ERROR geneva lausanne appended to https://www.metrolinemap.com/metro/lausanne/ adana appended to https://www.metrolinemap.com/metro/adana/ ankara appended to https://www.metrolinemap.com/metro/ankara/ bursa appended to https://www.metrolinemap.com/metro/bursa/ istanbul appended to https://www.metrolinemap.com/metro/istanbul/ izmir appended to https://www.metrolinemap.com/metro/izmir/ glasgow appended to https://www.metrolinemap.com/metro/glasgow/ london appended to https://www.metrolinemap.com/metro/london/ newcastle appended to https://www.metrolinemap.com/metro/newcastle/ dnipro appended to https://www.metrolinemap.com/metro/dnipro/ kharkiv appended to https://www.metrolinemap.com/metro/kharkiv/ kiev appended to https://www.metrolinemap.com/metro/kiev/
open('metrosx.json','w').write(json.dumps(metros))
6443467
import zipfile
zipfile.ZipFile('metrosx.zip', "w", zipfile.ZIP_DEFLATED).write('metrosx.json')
metro=metros['https://www.metrolinemap.com/metro/budapest/']