def test_load_file(): create_file('text.txt') assert file_handler.load_file( 'text.txt') == 'some sample text\nsome second line\nand some third\n' os.remove('text.txt') assert file_handler.load_file( 'not_exist.txt') == 'No such file or directory: not_exist.txt'
def generate_content(self): from random import randrange self.add_title("License", font="size4") from file_handler import load_file li = load_file("../LICENSE.txt") c = load_file("../contributors.txt").split("\n") while "" in c: c.remove("") li = li.replace("The KLBFAX contributors", ", ".join(c)) self.add_wrapped_text(li)
def __init__(self): super(UKTempPage, self).__init__("324") self.title = "UK Temperature" self.tagline = "Why exactly do we live in Britain?" self.in_index = False from file_handler import load_file self.ordered_ids = [ i.rstrip("\n") for i in load_file("uk_coordinate_ids.txt").split("\n") ] self.temps = [99 for i in range(len(self.ordered_ids))]
def handle(client, addr): #handle websocket connection handshake.handshake(client) lock = threading.Lock() while 1: data = messaging.recv_data(client, 4096) if not data: break data = cgi.escape(data) file_name = file_handler.check_for_file(data) if file_name: data = file_handler.load_file(file_name) lock.acquire() [messaging.send_data(c, data) for c in clients] lock.release() print 'Client closed:', addr lock.acquire() clients.remove(client) lock.release() client.close()
def handle (client, addr): #handle websocket connection handshake.handshake(client) lock = threading.Lock() while 1: data = messaging.recv_data(client, 4096) if not data: break data = cgi.escape(data) file_name = file_handler.check_for_file(data) if file_name: data = file_handler.load_file(file_name) lock.acquire() [messaging.send_data(c, data) for c in clients] lock.release() print 'Client closed:', addr lock.acquire() clients.remove(client) lock.release() client.close()
def generate_content(self): from random import randrange self.add_title("Pi", font="size4") from file_handler import load_file pi = load_file("pi.txt") self.add_wrapped_text(pi)
from classifier import ClassificationPipeline import evaluator import nltk.classify.util from nltk.classify import MaxentClassifier from nltk.tokenize.toktok import ToktokTokenizer import datetime import time import random from random import shuffle #load files truth = file_handler.load_file("test_samples/GenderEs", True); tweets = file_handler.load_file("test_samples/GenderEs", True); formatted_input = []; for i in truth: formatted_input.append((tweets[i], truth[i])); shuffle(formatted_input); print("Imported data"); stance_pipeline = ClassificationPipeline(); gender_pipeline = ClassificationPipeline(); gender_classifier = None; stance_classifier = None;
def test_load_file(): create_file('text.txt') assert file_handler.load_file('text.txt') == 'some sample text\nsome second line\nand some third\n' os.remove('text.txt') assert file_handler.load_file('not_exist.txt') == 'No such file or directory: not_exist.txt'
def generate_content(self): self.add_title("e", font="size4") from file_handler import load_file pi = load_file("e.txt") self.add_wrapped_text(pi)
def generate_content(self, debug=False): from file_handler import load_file clock = load_file("clock.txt").split("\n") clock = [[j == "X" for j in i] for i in clock] minute = [[False] * len(i) for i in clock] hour = [[False] * len(i) for i in clock] current_minute = float(now().strftime("%M")) current_hour = float(now().strftime("%I")) current_weekday = now().strftime("%a") if current_weekday == "Mon": bgcolor = "LIGHTRED" if current_weekday == "Tue": bgcolor = "YELLOW" if current_weekday == "Wed": bgcolor = "LIGHTCYAN" if current_weekday == "Thu": bgcolor = "LIGHTGREEN" if current_weekday == "Fri": bgcolor = "PINK" if current_weekday == "Sat": bgcolor = "LIGHTBLUE" if current_weekday == "Sun": bgcolor = "RED" self.add_title(now().strftime("%A %-d %b"), bg=bgcolor, fg="BLACK") circle_radius = 19 screen_radius = 19 d = .3 num_points = 25 current_hourtopointat = current_hour + current_minute / 60. for a in range(0, num_points + 1): r = circle_radius * a * .5 / num_points hx = r * cos(pi / 2 - current_hourtopointat * 2 * pi / 12) hy = r * sin(pi / 2 - current_hourtopointat * 2 * pi / 12) for dx in [-d, d]: for dy in [-d, d]: hour_x = screen_radius + int(floor(hx + .5 + dx)) hour_y = screen_radius - int(floor(hy + .5 + dy)) hour[hour_y][hour_x] = True r = circle_radius * a * .8 / num_points mx = r * cos(pi / 2 - current_minute * 2 * pi / 60) my = r * sin(pi / 2 - current_minute * 2 * pi / 60) for dx in [-d, d]: for dy in [-d, d]: minute_x = screen_radius + int(floor(mx + .5 + dx)) minute_y = screen_radius - int(floor(my + .5 + dy)) minute[minute_y][minute_x] = True output = "" for y in range(0, 2 * screen_radius + 1): for x in range(0, 2 * screen_radius + 1): if clock[y][x] or minute[y][x] or hour[y][x]: output += "X" else: output += " " output = output + " " * (2 * screen_radius + 1) output2 = "" for y in range(0, 2 * screen_radius + 1, 2): output2 = output2 + " " * (screen_radius + 1) for x in range(0, 2 * screen_radius + 1): letter0 = output[y * (2 * screen_radius + 1) + x] letter1 = output[(y + 1) * (2 * screen_radius + 1) + x] if letter0 == " " and letter1 == " ": output2 = output2 + " " elif letter0 == "X" and letter1 == "X": output2 = output2 + u"\u2588" elif letter0 == "X" and letter1 == " ": output2 = output2 + u"\u2580" else: output2 = output2 + u"\u2584" if y != 2 * screen_radius: output2 = output2 + "\n" self.add_text(output2)