Created
December 15, 2014 18:39
-
-
Save atiaxi/a5c451ef27da65d4fa50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#### PEP8: econ_buffs.py | |
""" | |
Created on Sun Dec 14 14:49:05 2014 | |
@author: boggs | |
Module to retrieve defensive buffs from Chromeconomist's DB | |
""" | |
import socket | |
host = "ec2-54-191-166-247.us-west-2.compute.amazonaws.com" | |
port = 17236 | |
size = 1024 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
#### I mentioned this in the other file, but you don't want to create a connection on import. | |
#### If e.g. your server were down, chromabot wouldn't run because it wouldn't get past | |
#### the 'import EconBuffs' step | |
def getEconBuffs(territory): | |
"""takes the territory name as the first argument. Please don't use the subreddit format | |
e.g. "/r/MidnightMarsh" """ | |
s.connect((host,port)) | |
s.send(territory) | |
data = s.recv(size) | |
s.close() | |
#### Probably need to catch exceptions, allow for a timeout | |
parts = data.split(':') | |
context = parts[0] | |
if context != 'ERROR': | |
buff = float(parts[1]) | |
return buff | |
else: | |
return 0.0 | |
#### Zero might, somehow, be a valid buff; you could return None instead | |
if __name__ == '__main__': | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment