Guest User

url_finder.py

a guest
Apr 20th, 2020
346
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import urllib.request
  2. import json
  3.  
  4. urls = [
  5.     "http://download.gameforge.com/metin2_20171214/clients/{country_url}/Metin2_{timestamp}_softonic.exe",
  6.     "http://download.gameforge.com/metin2_20171214/clients/{country_url}/Metin2_{country_file}_{timestamp}.exe",
  7. ]
  8.  
  9. country_codes = [
  10.     "us", "en", "de", "fr", "ro", "it", "tr", "pl", "es", "pt", "dk",
  11.     "nl", "cz", "hu", "gr", "ru", "ae",
  12. ]
  13.  
  14. timestamps = [
  15.     "20081204",
  16.     "20111216",
  17.     "20100528",
  18. #    "20080811",
  19. #    "20090526",
  20. #    "20091214",
  21. #    "20100421",
  22. ]
  23.  
  24.  
  25. def discover_timestamp(timestamp):
  26.     hits = []
  27.     possible_urls = []
  28.  
  29.     for country in country_codes:
  30.         for url in urls:
  31.             normal_url = url.format(timestamp=timestamp, country_url=country, country_file=country)
  32.             upper_url = url.format(timestamp=timestamp, country_url=country, country_file=country.upper())
  33.  
  34.             possible_urls.append({
  35.                 'url': normal_url,
  36.                 'country': country,
  37.             })
  38.  
  39.             if normal_url != upper_url:
  40.                 possible_urls.append({
  41.                     'url': upper_url,
  42.                     'country': country,
  43.                 })
  44.  
  45.     for url in possible_urls:
  46.         try:
  47.             status = urllib.request.urlopen(url['url']).getcode()
  48.             if status == 200:
  49.                 hits.append(url)
  50.             else:
  51.                 print(status)
  52.         except Exception:
  53.             pass
  54.  
  55.     print("Valid URLs found for timestamp {}: {}".format(timestamp, len(hits)))
  56.  
  57.     return hits
  58.  
  59.  
  60. def get_links():
  61.     download_urls = []
  62.     for timestamp in timestamps:
  63.         print("Checking timestamp {}...".format(timestamp))
  64.         download_urls += discover_timestamp(timestamp)
  65.     return download_urls
  66.  
  67.  
  68. links = get_links()
  69. with open("links.json", "w") as file:
  70.     json.dump(links, file)
  71.  
  72. print("Done.")
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×