Guest User

Untitled

a guest
Jun 18th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. import string
  2. import logging
  3. import requests
  4. import json
  5. import dateutil.parser
  6. import datetime
  7. import re
  8.  
  9. from requests.adapters import HTTPAdapter
  10. from requests.packages.urllib3.util.retry import Retry
  11.  
  12. http = requests.Session()
  13. logging.basicConfig(level=logging.DEBUG)
  14.  
  15. retries = Retry(total=5, backoff_factor=2, status_forcelist=[ 502, 503, 504, 429, 403])
  16. http.mount('https://', HTTPAdapter(max_retries=retries))
  17.  
  18. headers = {
  19.   "Accept": "application/vnd.bountysource+json; version=1",
  20.   "Accept-Encoding": "gzip, deflate, br",
  21.   "Accept-Language": "en-US,en;q=0.9",
  22.   "Cache-Control": "no-cache",
  23.   "Connection": "keep-alive",
  24.   "Host": "api.bountysource.com",
  25.   "Origin": "https://www.bountysource.com",
  26.   "Pragma": "no-cache",
  27.   "Referer": "https://www.bountysource.com/",
  28.   "Sec-Fetch-Dest": "empty",
  29.   "Sec-Fetch-Mode": "cors",
  30.   "Sec-Fetch-Site": "same-site",
  31. }
  32.  
  33. #print(http.get('https://api.bountysource.com/search/bounty_search?callback=CORS&order=earliest_bounty&page=2&per_page=250', headers=headers).text)
  34.  
  35. regex = re.compile(r"\)\w*$")
  36. def clean_json(x):
  37.   x = x.replace('CORS(', '')
  38.   x = x.replace(")\n", '')
  39.   x = x.replace('/**/ ', '')
  40.   x = regex.sub('', x)
  41.   return x
  42.  
  43. TWO_YEARS = 365 * 2
  44. total = 0
  45. bounties = 0
  46. page = 0
  47. now = datetime.datetime.now()
  48. while True:
  49.   url = "https://api.bountysource.com/search/bounty_search?callback=CORS&direction=asc&order=earliest_bounty&page=%s&per_page=250" % (page)
  50.   text = clean_json(http.get(url, headers=headers).text)
  51.   for issue in json.loads(text)['data']['issues']:
  52.     #print(issue)
  53.     then = dateutil.parser.isoparse(issue['created_at']).replace(tzinfo=None)
  54.     #print((now-then).days)
  55.     if (now - then).days > TWO_YEARS and issue['paid_out'] is False:
  56.       total += float(issue['bounty_total'])
  57.       bounties += 1
  58.   page += 1
  59.   print(total)
  60.   print(bounties)
Add Comment
Please, Sign In to add comment