Created
July 9, 2018 09:47
-
-
Save zanculmarktum/17b1ac8152c3afa4844c03634ecbbd0e to your computer and use it in GitHub Desktop.
Get the last post number from 4chan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from __future__ import print_function | |
import sys | |
if sys.version_info[0] == 3: | |
import urllib.request as urllib | |
else: | |
import urllib2 as urllib | |
import json | |
def usage(): | |
print("Usage: %s board" % sys.argv[0], file=sys.stderr) | |
def main(args): | |
try: | |
board = args[0] | |
except: | |
usage() | |
sys.exit(1) | |
f = urllib.urlopen('https://a.4cdn.org/%s/1.json' % board) | |
data = json.load(f) | |
f.close() | |
t = 0 | |
while True: | |
try: | |
data['threads'][t]['posts'][0]['sticky'] | |
except: | |
break | |
t += 1 | |
p = 0 | |
while True: | |
try: | |
data['threads'][t]['posts'][p] | |
except: | |
p -= 1 | |
break | |
p += 1 | |
print(data['threads'][t]['posts'][p]['no']) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment