Source files for the neveragain.tech site
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

  1. #!/usr/bin/env python
  2. import commands
  3. import re
  4. import requests
  5. import sys
  6. import os
  7. token = os.environ['GITHUB_ACCESS_TOKEN']
  8. def errprint(s):
  9. sys.stderr.write(s)
  10. sys.stderr.flush()
  11. prs = []
  12. for page in range(1, 10):
  13. more_prs = requests.get('https://api.github.com/repos/neveragaindottech/neveragaindottech.github.io/pulls?access_token=%s&page=%d' % (token, page)).json()
  14. prs += more_prs
  15. errprint('fetched %d PRs\n' % len(prs))
  16. if not more_prs:
  17. break
  18. for pr in reversed(prs):
  19. pr_num = pr['number']
  20. author = pr['user']['login']
  21. errprint('PR #%s from %s: ' % (pr_num, author))
  22. diff_lines = commands.getoutput('./pr-diff %s' % pr_num).strip().split('\n')
  23. if len(diff_lines) == 1 and diff_lines[0].startswith('+<'):
  24. line = diff_lines[0].lstrip('+')
  25. props = {}
  26. props['github_user'] = author
  27. props['pull_request_number'] = str(pr_num)
  28. match = re.search(r'<a *href *= *"([^"]*)', line, re.I)
  29. props['link'] = match and match.group(1)
  30. text_line = re.sub(r'<[^>]*>', '', line)
  31. parts = text_line.split(',', 2)
  32. if len(parts) == 3:
  33. props['name'], props['occupation_title'], props['affiliation'] = parts
  34. elif len(parts) == 2:
  35. props['name'], props['affiliation'] = parts
  36. else:
  37. props['name'] = text_line
  38. filename = '../_signatures/%s.md' % author
  39. if os.path.exists(filename):
  40. errprint('%s ALREADY EXISTS\n' % filename)
  41. continue
  42. with open(filename, 'w') as file:
  43. file.write('---\n')
  44. for key, value in props.items():
  45. value = value and value.strip()
  46. if value:
  47. file.write(' %s: %s\n' % (key, value))
  48. file.write('---\n')
  49. errprint('ok, made %s\n' % filename)
  50. else:
  51. errprint('BAD; diff is:\n')
  52. errprint(' ' + '\n '.join(diff_lines) + '\n')