Last active
July 2, 2023 10:29
-
-
Save bertini36/9f47f7cca3221603444d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
# coding=utf-8 | |
import requests | |
# Track ids to download | |
tracks = [ | |
'9319946', | |
'9319955', | |
... | |
] | |
# Different users to login | |
users = [ | |
{"email":"[email protected]", "password":"password"}, | |
{"email":"[email protected]", "password":"password"}, | |
... | |
] | |
# Different proxys to download tracks | |
proxies = [ | |
{"http": "http://XX.XX.XX.XX:PP/"}, | |
{"http": "http://YY.YY.YY.YY:PP/"}, | |
... | |
] | |
def login(credentials): | |
login_url = 'http://es.wikiloc.com/wikiloc/login.do' | |
headers = { | |
'Cache-Control': 'no-cache', | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Host': 'es.wikiloc.com' | |
} | |
session = requests.session() | |
session.post(login_url) | |
session.post(login_url, data=credentials, headers=headers) | |
return session | |
def downloadGpx(session, track_id, proxy): | |
download_url = 'http://es.wikiloc.com/wikiloc/downloadToFile.do?event=download&id={}&format=gpx'.format(track_id) | |
response = session.get(download_url, stream=True, proxies=proxy) | |
status_code = response.status_code | |
if status_code == 200: | |
f = open("gpx/" + track_id + ".gpx", 'wb') | |
inside = False | |
for chunk in response.iter_content(chunk_size=1024): | |
inside = True | |
if chunk: | |
f.write(chunk) | |
f.close() | |
if inside == False: status_code = -1 | |
return status_code | |
def downloadTracks(): | |
user = 0 | |
proxy = 0 | |
session = login(users[user]) | |
for track_id in tracks: | |
try: | |
status_code = downloadGpx(session, track_id, proxies[proxy]) | |
except: | |
status_code = 0 | |
pass | |
while status_code != 200: | |
if status_code == -1: | |
user = 0 if user == len(users)-1 else user = user + 1 | |
session = login(users[user]) | |
else: | |
proxy = 0 if proxy == len(proxies)-1 else proxy = proxy + 1 | |
try: | |
status_code = downloadGpx(session, track_id, proxies[proxy]) | |
except: | |
status_code = 0 | |
pass | |
print "CHIM-PUM" | |
def main(): | |
downloadTracks() | |
if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bertini36 there is an inconsistent mix of tabs and spaces in your code
Even after fixing it (minor Python 2 -> 3 changes) I haven't been able to make this script work again.