<commit_before>#!/usr/bin/env python

import web
import hashlib
import random
import time

rval = 0

try:
	controldb = web.database(dbn='sqlite', db='/etc/fsart/control')
except:
	rval = 1	

urls = (
	'/', 'status',
	'/config', 'config',
	'/err', 'error'
	'/mdbupdate', 'master_db_update',
	'/nt', 'newtarget',
	'/nm', 'newmaster',
	'/jobadd', 'job_add',
	'/jobcancel', 'job_cancel',
)

web.config.debug = True

app = web.application(urls, globals())

def hasmaster():
	if rval = 0:
		try:
			masters = controldb.query("SELECT COUNT FROM masters")
			if masters > 1:
				rval = 2
		except:
			rval = 1
	if rval > 0:
		global gmrval = rval
		raise web.seeother('/err')
	else:
		global gmrval = None
	
def getstatus():
	
class status:

class error:
	if web.ctx.query = human:
	
	else:
		return gmrval
	
class job_cancel:
	
app.add_processor(web.loadhook(getstatus))
	
if __name__ == "__main__":
	app.run()<commit_msg>even more work on worker code<commit_after>#!/usr/bin/env python

import web
import hashlib
import random
import time
import re

rval = 0

# handle connection to control database.  if it doesn't exist this thing
# will not start.
def controlconnect():
	try:
		controldb = web.database(dbn='sqlite', db='/fsart/cdb.sqlite3')
	except:
		return 1
	else:
		return 0

global gmrval = controlconnect()
		
urls = (
	'/', 'status',
	'/config', 'config',
	'/err', 'error'
	'/mdbupdate', 'master_db_update',
	'/nt', 'newtarget',
	'/nm', 'newmaster',
	'/jobadd', 'job_add',
	'/jobcancel', 'job_cancel',
)

web.config.debug = True

app = web.application(urls, globals())

# this problem-checking code will run every time a request is made.
# is the control db [still] available?  do we have a master configured?
def hasmaster():
	if gmrval == 1:
		rval = controlconnect()
	else:	
		try:
			masters = controldb.query("SELECT COUNT FROM masters")
			if masters < 1:
				rval = 3
		except:
			rval = 1
	if rval > 0:
		global gmrval = rval
		# show the error page if there is one
		raise web.seeother('/err')
	else:
		global gmrval = 0
		
def ishuman():
	mq = web.ctx.query
	if "human" in mq.lower():
		web.header('Content-type', "text/html; charset=utf-8")
		

# what is the status of the worker?  is it busy?  what is it doing?
class status:
	mq = web.ctx.query
	if "human" in mq.lower():

class error:
	def GET(self):
		mq = web.ctx.query
		if "human" in mq.lower():
	
	else:
		return gmrval
	
class job_cancel:
	
app.add_processor(web.loadhook(hasmaster))
app.add_processor(ishuman)
	
if __name__ == "__main__":
	app.run()
{'fraction_non_alphanumeric': 0.14455445544554454, 'fraction_numerical': 0.007128712871287129, 'mean_word_length': 3.6094890510948905, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1163231', 'n_tokens_mistral': 1036, 'n_tokens_neox': 944, 'n_words': 277}