Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import unirest
import time
import urllib2
import json
SCREEN_NAME = "ffranz"
SIZE = "original"
SLASH = "/"
SLEEP_TIME = 90
AVATAR_API = "http://api.snaptwit.com/avatar/"
NUDE_API = "http://api.sightengine.com/1.0/nudity.json"
API_USER = "**USER**"
API_SECRET = "**SECRET**"
#if os.fork():
# print "Working in background... See you!"
# sys.exit()
while True:
# get avatar
avatar_response = urllib2.urlopen(AVATAR_API+SCREEN_NAME+"/"+SIZE)
if avatar_response.code == 200:
# check nude
nude_response = unirest.get(NUDE_API,
params={
"api_user":API_USER,
"api_secret":API_SECRET,
"url":avatar_response.geturl()
}
);
if nude_response.code == 200:
if nude_response.body['nudity']['result']:
# store photo
image_response = unirest.get(AVATAR_API+SCREEN_NAME+"/"+SIZE)
if image_response.code == 200:
image_file = 'photo-confidence-'+str(nude_response.body['nudity']['confidence'])+"-percent-"+str(int(time.time()))+".png"
data_file = open(image_file,'wb')
data_file.write(image_response.raw_body)
data_file.close()
time.sleep(SLEEP_TIME*60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment