Skip to content

Instantly share code, notes, and snippets.

@initrunlevel0
Created July 11, 2014 06:18
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 initrunlevel0/1936ebeb5645d674f7a3 to your computer and use it in GitHub Desktop.
Save initrunlevel0/1936ebeb5645d674f7a3 to your computer and use it in GitHub Desktop.
Skrip pengambil data C1 KPU lembar ke-4
import requests
import base64
def ambil_c1(id_kelurahan, id_tps):
r = requests.get('http://scanc1.kpu.go.id/viewp.php?f=' + str(id_kelurahan).zfill(7) + str(id_tps).zfill(3) + '04.jpg')
content_type = r.headers['content-type']
if(content_type == "text/html"):
return None
else:
id_to_print = str(id_kelurahan).zfill(7) + str(id_tps).zfill(3)
with open(id_to_print + '.jpg', 'wb') as f:
for chunk in r.iter_content():
f.write(chunk)
return base64.b64encode(r.content)
def main():
for id_kelurahan in range(1, 85000):
finish = False
id_tps = 1
while(finish == False):
get = ambil_c1(id_kelurahan, id_tps)
id_to_print = str(id_kelurahan).zfill(7) + str(id_tps).zfill(3)
if (get != None):
print "Mengambil data dari " + id_to_print + ": TERSEDIA"
id_tps = id_tps + 1
pass
else:
print "Mengambil data dari " + id_to_print + ": TIDAK TERSEDIA"
finish = True
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment