A command line (CLI) program for monitoring and downloading 8chan threads. Licensed under MIT.
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.

helpers.py 897B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import datetime
  2. import re
  3. import time
  4. def parse_url(url):
  5. """Extracts the board name and thread no from a URL.
  6. """
  7. parts = url.split('#', 1)
  8. board, thread_no = re.findall('(\w+)\/res\/(\d+)', parts[0])[0]
  9. anchored_reply = '' if len(parts)<2 else re.findall('q?(\d+)$', parts[1])[0]
  10. return [board, thread_no, anchored_reply]
  11. def timestamp_now():
  12. return int(time.time())
  13. def timestamp_to_date(t):
  14. d = datetime.datetime.fromtimestamp(t).strftime('%Y-%m-%d %H:%M:%S')
  15. return d
  16. def generate_thread_json_url(board, thread_no):
  17. url = 'https://8ch.net/{}/res/{}.json'.format(board, thread_no)
  18. return url
  19. def generate_thread_html_url(board, thread_no):
  20. url = 'https://8ch.net/{}/res/{}.html'.format(board, thread_no)
  21. return url
  22. def generate_file_url(filename):
  23. url = 'https://media.8ch.net/file_store/{}'.format(filename)
  24. return url