Skip to content

Instantly share code, notes, and snippets.

@nmcv
Created April 1, 2014 22:04
Show Gist options
  • Save nmcv/9924038 to your computer and use it in GitHub Desktop.
Save nmcv/9924038 to your computer and use it in GitHub Desktop.
Used to mine unicoins @ stackoverflow.com on April 1
#!/bin/env python3
import re
import time
import requests
sleep_time = 10
needs_sleep = False
# Target-related
cookie_jar = {'usr': 't=xxxxxxxxxxx&s=xxxxxxxxxxxx'} # change this only
mine_url = 'https://stackoverflow.com/unicoin/mine?rock='
new_rock_url = 'https://stackoverflow.com/unicoin/rock?_='
fkey_pattern = '<input id="fkey" name="fkey" type="hidden" value="([a-fA-F0-9]{32})">'
headers = \
{
'Accept':'*/*',
'Accept-Encoding':'gzip,deflate,sdch',
'Accept-Language':'en-US,en;q=0.8,it;q=0.6,ru;q=0.4,tr;q=0.2',
'Cache-Control':'no-cache',
'Connection':'keep-alive',
'Cookie': 'usr=' + cookie_jar['usr'] + '; gauthed=1;',
'DNT':'1',
'Host':'stackoverflow.com',
'Pragma':'no-cache',
'Referer':'https://stackoverflow.com/questions/8306654/finding-all-possible-permutations-of-a-given-string-in-python',
'User-Agent':'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)',
'X-Requested-With':'XMLHttpRequest'
}
# Let's rock
while 1:
if needs_sleep:
print("Sleeping for {}s".format(sleep_time))
time.sleep(sleep_time)
# Get a rock
print("Requesting new rock ...")
timestamp = str(int(time.time()))
try:
new_rock = requests.get(new_rock_url + timestamp, headers=headers)
new_rock_id = new_rock.json().get('rock')
print("Fetched rock {}".format(new_rock_id))
except:
print("Couldn't even fetch a new rock - probably needs another cookie. Quit.")
exit(1)
# Fetch an 'fkey'
fkey_raw = re.search(fkey_pattern, new_rock.text, flags=re.M)
fkey = fkey_raw.group(1)
payload = \
{
'fkey': fkey
}
# Request mining verification
print("Requesting mining proof of {} ...".format(new_rock_id))
headers['Content-Type'] = 'application/x-www-form-urlencoded'
try:
mine_request = requests.post(mine_url + new_rock_id, data=payload, cookies=cookie_jar)
except Exception as e:
print("Couldn't make a request. Error was: {}".format(e))
continue
# Get the resulting JSON
try:
mining_result = mine_request.json().get('result')
mining_value = mine_request.json().get('value')
except Exception as e:
print("Something was uncool. Will try again.")
needs_sleep = True
continue
if mining_result == "Success":
print("Mining done, value was {}".format(mining_value))
needs_sleep = True
else:
print("Mining {} failed".format(new_rock_id))
needs_sleep = False
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment