Advertisement
Guest User

gosms.py

a guest
Nov 20th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. import argparse
  2. import requests
  3. import time
  4. import math
  5. from threading import Thread
  6. from random import choice
  7. from random import randint
  8. from string import digits
  9. from sys import exit
  10.  
  11. symbdict = 'abcdf' + digits
  12. def genp():
  13.     return ''.join(choice(symbdict) for i in range(randint(4, 6)))
  14.    
  15. parser = argparse.ArgumentParser(description='GOSMS downloader 2.0')
  16. parser.add_argument('-c', action="store", dest="count", default=5, type=int)
  17. parser.add_argument('-o', action="store", dest="out", default='')
  18. parser.add_argument('-t', action="store", dest="threads", default=1, type=int)
  19.  
  20. args = parser.parse_args()
  21. count = args.count
  22. tcount = args.threads
  23. path = args.out
  24.  
  25. if path != '' and path[len(path):] != '\\':
  26.     path = path + '\\'
  27.  
  28. if tcount > count:
  29.     print("The count of threads should not exceed the url's count")
  30.     exit()
  31.    
  32. class dlThread(Thread):
  33.     def __init__(self, task):
  34.         Thread.__init__(self)
  35.         self.task = task
  36.        
  37.     def run(self):
  38.         for self.i in range(self.task):
  39.             self.gen = genp()
  40.             self.url = 'https://gs.3g.cn/D/' + self.gen + '/c'
  41.             self.response = requests.get(self.url)
  42.            
  43.             if self.response.url != self.url and self.response.status_code == 200:
  44.                 self.url = self.response.url
  45.                 self.f = open(path + self.gen + self.url[self.url.find('.', self.url.find('com/')):], 'wb')
  46.                 self.f.write(self.response.content)
  47.                 self.f.close()
  48.                
  49.                 print(self.gen + " downloaded")
  50.             else:
  51.                 print(self.gen + "is error!")
  52.  
  53. threads = []
  54. rest = count
  55. for i in range(tcount):
  56.     if rest >= 0:
  57.         threads.append(dlThread(math.ceil(count/tcount)))
  58.     else:
  59.         threads.append(dlThread(rest + math.ceil(count/tcount)))
  60.        
  61.     threads[i].start()
  62.    
  63. # Coded by MorphEdAlign
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement