Skip to content

Instantly share code, notes, and snippets.

@zanculmarktum
Created July 9, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanculmarktum/17b1ac8152c3afa4844c03634ecbbd0e to your computer and use it in GitHub Desktop.
Save zanculmarktum/17b1ac8152c3afa4844c03634ecbbd0e to your computer and use it in GitHub Desktop.
Get the last post number from 4chan
#!/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