Skip to content

Instantly share code, notes, and snippets.

@Zadigo
Created June 28, 2020 20:18
Show Gist options
  • Save Zadigo/eae296bad36786c1c44e8a8ce5cdd17a to your computer and use it in GitHub Desktop.
Save Zadigo/eae296bad36786c1c44e8a8ce5cdd17a to your computer and use it in GitHub Desktop.
import argparse
import os
import threading
import time
from urllib import parse
import requests
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
LOG = os.path.join(BASE_DIR, 'responses.html')
PROXIES = {
'http': ''
}
DATA = {
'q': ''
}
def writer(func):
def wrapper(**kwargs):
with open(LOG, 'a') as f:
# Func() is get or post
# method below
response = func()
if response:
f.write(response.text)
f.write('\n')
return wrapper
@writer
def post():
response = requests.post(url, data=DATA, proxies=PROXIES)
if response:
print('Success for @ %s' % url)
return response
return None
@writer
def get():
params = parse.urlencode(DATA)
constructed_url = url + '?' + params
response = requests.post(constructed_url, proxies=PROXIES)
if response:
print('Success for @ %s' % constructed_url)
return response
return None
def run(method='get'):
if method == 'get':
using = get
else:
using = post
# Using the wrapper() function above
# which is executed in the thread
thread = threading.Thread(target=using)
thread.start()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-p', help='Proxy', type=str, required=False)
args = parser.parse_args()
if args.p:
PROXIES.update({'http': args.p})
while True:
run(method='get')
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment