Esempio n. 1
0
def import_gbfavs(password, userID):
	import xml.etree.ElementTree as ET
	
	favIDs = []
	offset = 0
	while True:
		data = urllib2.urlopen('http://gelbooru.com/index.php?page=favorites&s=view&id=%s&pid=%s' % (userID, offset)).read()
		
		matches = re.findall(r'href=\"index\.php\?page=post&s=view&id=(\d+)\"', data)
		if len(matches) == 0:
			break
		favIDs += matches
		offset = offset + len(matches)
	print "Found %s Favorites!" % len(favIDs)
	
	ctx = app.test_request_context()
	ctx.push()
	
	g.db = db_connect(password)
	
	for favID in reversed(favIDs):
		print "Downloading http://gelbooru.com/index.php?page=post&s=view&id=%s" % favID
		data = urllib2.urlopen('http://gelbooru.com/index.php?page=dapi&s=post&q=index&id=%s' % favID).read()
		root = ET.fromstring(data)
		if len(root) < 1:
			print "--> Not Found!"
		
		d = root[0].attrib
		
		post = Post.download(
			url=d['file_url'],
			tagnames=d['tags'].strip().split(' '),
			rating=d['rating']
		)
	ctx.pop()
Esempio n. 2
0
def dbshell(password):
	#db = dbapi2.connect(path(settings.DB_NAME))
	#db.execute("PRAGMA key = '%s'" % re.escape(password))
	db = db_connect(password)
	while True:
		try:
			cmd = raw_input("> ")
			if cmd == '.q':
				return
			
			res = db.execute(cmd).fetchall()
			for row in res:
				if type(row) == tuple:
					print ', '.join([str(i) for i in row])
				else:
					print row
		except Exception as e:
			print "%s: %s" % (e.__class__.__name__, e)