<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

import zmq
import argparse
import urllib2
import bs4
import datetime
import time

def retrieve_occupancy():
	'''retrieves data from the carolus thermen homepage'''
	request = urllib2.Request(
		'http://www.carolus-thermen.de/go/auslastung/english.html',
		headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'}
	)
	data = urllib2.urlopen(request).read()
	tree = bs4.BeautifulSoup(data)

	occupancy = {}
	# update timestamp
	datestring = ' '.join( (e.getText() for e in tree('p', id='last_update')[0]('strong') ) )
	for suffix in ['th','st','nd','rd']:
		try:
			occupancy['update'] = datetime.datetime.strptime(datestring, '%B  %d' + suffix + '          \n, %Y  %I:%M %p')
			break
		except:
			pass

	# occupancy data
	categories = ['thermen', 'sauna', 'garage']
	for i,div in enumerate(tree.div(id='box_auslastungen')[0].find_all('div', 'inner')):
		occupancy[categories[i]] = int(div['style'][6:-2])

	return occupancy

def main(host, port):
	# connect
	context = zmq.Context.instance()
	publisher = context.socket(zmq.PUB)
	publisher.connect("tcp://{0}:{1}".format(host, port))

	# save previous timestamp that updates are recognized
	previous_update = datetime.datetime.min
	print 'press [CTRL] + [C] to quit'
	while True:
		try:
			occupancy = retrieve_occupancy()
			if occupancy['update'] > previous_update:
				previous_update = occupancy['update']
				for topic in ['update', 'thermen', 'sauna', 'garage']:
					publisher.send_multipart(['/carolus/{0}'.format(topic), str(occupancy[topic])])
<commit_msg>fixed carolus thermen publisher<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

import zmq
import argparse
import urllib2
import bs4
import datetime
import time

def retrieve_occupancy():
	'''retrieves data from the carolus thermen homepage'''
	request = urllib2.Request(
		'http://www.carolus-thermen.de/go/auslastung/english.html',
		headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'}
	)
	data = urllib2.urlopen(request).read()
	tree = bs4.BeautifulSoup(data)

	occupancy = {}
	# update timestamp
	datestring = ' '.join( (e.getText() for e in tree('p', id='last_update')[0]('strong') ) )
	for suffix in ['th','st','nd','rd']:
		try:
			occupancy['update'] = datetime.datetime.strptime(datestring, '%B  %d' + suffix + '          \n, %Y  %I:%M %p')
			break
		except:
			pass

	# occupancy data
	occupancy_div = tree.div(id='box_auslastungen')[0]
	for i, category in zip([10, 20, 30], ['thermen', 'sauna', 'garage']):
		bar_div = occupancy_div.find_all('div', id=i)[0].find_all('div', 'inner')
		if len(bar_div) == 1:
			occupancy[category] = int(bar_div[0]['style'][6:-2])

	return occupancy

def main(host, port):
	# connect
	context = zmq.Context.instance()
	publisher = context.socket(zmq.PUB)
	publisher.connect("tcp://{0}:{1}".format(host, port))

	# save previous timestamp that updates are recognized
	previous_update = datetime.datetime.min
	print 'press [CTRL] + [C] to quit'
	while True:
		try:
			occupancy = retrieve_occupancy()
			if occupancy['update'] > previous_update:
				previous_update = occupancy['update']
				for topic in ['update', 'thermen', 'sauna', 'garage']:
					if topic in occupancy:
						publisher.send_multipart(['/carolus/{0}'.format(topic), str(occupancy[topic])])

{'fraction_non_alphanumeric': 0.17457024303497332, 'fraction_numerical': 0.02222880853586248, 'mean_word_length': 4.569306930693069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4072320', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1218, 'n_words': 271}