Skip to content

Commit

Permalink
cleaned up ssl stuff in hit_server
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Dec 25, 2015
1 parent e21d1de commit 6bea513
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion anagramatron/anagramstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __str__(self):
seen_perc = self.stats['passed_filter']/(self.stats['tweets_seen'] or 1)
seen_perc *= 100
runtime = time.time() - self.start_time
cache_hit_perc = (self['cache_hits'] / (self['possible_hits'] + self['fetch_pool_size'] + self['cache_hits'])) * 100
cache_hit_perc = (self['cache_hits'] / ((self['possible_hits'] + self['fetch_pool_size'] + self['cache_hits']) or 1)) * 100
status = "seen %d, used %d (%0.1f%%), hits(/in cache) %d/%d (%0.1f%%), \
agrams %d, cachesize %d, buffered %d, runtime %s" % (
self['tweets_seen'], self['passed_filter'], seen_perc,
Expand Down
3 changes: 3 additions & 0 deletions anagramatron/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def __setup_data_dir():
if not os.path.exists(ANAGRAM_DATA_DIR):
os.mkdir(ANAGRAM_DATA_DIR)

ANAGRAM_BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
ANAGRAM_SEC_DIR = os.path.join(ANAGRAM_BASE_DIR, 'sec')

ANAGRAM_CACHE_SIZE = 200000
ANAGRAM_STREAM_BUFFER_SIZE = 20000

Expand Down
23 changes: 14 additions & 9 deletions anagramatron/hit_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from bottle import (Bottle, run, request, server_names,
ServerAdapter, abort)

from . import hitmanager, anagramstats
from . import hitmanager, anagramstats, common

from .hitmanager import (HIT_STATUS_REVIEW, HIT_STATUS_SEEN,
HIT_STATUS_POSTED, HIT_STATUS_APPROVED)
Expand All @@ -27,16 +27,21 @@ def run(self, handler):
handler,
numthreads=1,
max=1)
# If cert variable is has a valid path, SSL will be used
# If cert path exists SSL will be used
# You can set it to None to disable SSL
cert_path = 'data/server.pem' # certificate path
if os.path.exists(cert_path):
cert = cert_path
# cert_path = 'data/server.pem' # certificate path
if os.path.exists(common.ANAGRAM_SEC_DIR):
cert = os.path.join(common.ANAGRAM_SEC_DIR, 'cert.pem')
priv = os.path.join(common.ANAGRAM_SEC_DIR, 'privkey.pem')
assert os.path.exists(cert) and os.path.exists(priv), 'missing SSL credential'

server.ssl_certificate = cert
server.ssl_private_key = cert
server.ssl_module = 'builtin'

print('running with ssl')
else:
cert = None
print('WARNING: no cert found, running without SSL')
server.ssl_certificate = cert
server.ssl_private_key = cert
print('no cert found, running without ssl')
try:
server.start()
finally:
Expand Down
2 changes: 1 addition & 1 deletion anagramatron/hitmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def new_hit(self, first, second):
hit = {
"id": int(time.time()*1000),
"status": HIT_STATUS_REVIEW,
"hash": first['tweet_hash'],
"hash": first['anagram_hash'],
"tweet_one": first,
"tweet_two": second
}
Expand Down
2 changes: 1 addition & 1 deletion anagramatron/multidbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __contains__(self, item):
def __getitem__(self, key):
for db in self._data:
if key in db:
return anagramfunctions.decodetweet(db[key].decode('utf-8'))
return anagramfunctions.decode_tweet(db[key].decode('utf-8'))
raise KeyError

def __setitem__(self, key, value):
Expand Down

0 comments on commit 6bea513

Please sign in to comment.