Skip to content

Commit

Permalink
pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
F483 committed Sep 3, 2015
1 parent 9724685 commit 67e6068
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dataserv/Farmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def ping(self):
"""
farmer = self.lookup()
time_limit = (datetime.utcnow() - farmer.last_seen).seconds >= app.config["MAX_PING"]
delta = datetime.utcnow() - farmer.last_seen
time_limit = delta.seconds >= app.config["MAX_PING"]

if time_limit:
farmer.last_seen = datetime.utcnow()
Expand Down
5 changes: 2 additions & 3 deletions dataserv/Validator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
def is_sha256(content):
"""Make sure this is actually an valid SHA256 hash."""
digits58 = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
digits58 = ('0123456789ABCDEFGHJKLMNPQRSTUVWXYZ'
'abcdefghijkmnopqrstuvwxyz')
for i in range(len(content)):
if not content[i] in digits58:
return False
return len(content) == 64


20 changes: 11 additions & 9 deletions dataserv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def online_farmers():
time_ago = current_time - datetime.timedelta(minutes=online_time)

# give us all farmers that have been around for the past online_time
return db.session.query(Farmer).filter(Farmer.last_seen > time_ago).order_by(desc(Farmer.height)).all()
q = db.session.query(Farmer)
q = q.filter(Farmer.last_seen > time_ago)
q = q.order_by(desc(Farmer.height))
return q.all()


# Routes
Expand Down Expand Up @@ -97,8 +100,8 @@ def get_address():

@app.route('/api/online', methods=["GET"])
def online():
# this could be formatted a bit better, but we just want to publicly display
# that status of the farmers connected to the node
# this could be formatted a bit better, but we just want to publicly
# display that status of the farmers connected to the node
output = ""
current_time = datetime.datetime.utcnow()
text = "{0} | Last Seen: {1} | Height: {2}<br/>"
Expand All @@ -112,13 +115,11 @@ def online():

@app.route('/api/online/json', methods=["GET"])
def online_json():
# this could be formatted a bit better, but we just want to publicly display
# that status of the farmers connected to the node

payload = {
"farmers": [json.loads(farmer.to_json()) for farmer in online_farmers()]
"farmers": [
json.loads(farmer.to_json()) for farmer in online_farmers()
]
}

return jsonify(payload)


Expand All @@ -132,7 +133,8 @@ def total():

# return in TB the number
app.config["BYTE_SIZE"] = 1024*1024*128
result = total_shards * (app.config["BYTE_SIZE"] / (1024*1024*1024*1024)) # bytes / 1 TB
byte_size = app.config["BYTE_SIZE"]
result = (total_shards * (byte_size / (1024 ** 4))) # bytes / 1 TB
json_data = {'id': randint(0, 9999999), 'total_TB': round(result, 2)}

return jsonify(json_data)
Expand Down
2 changes: 1 addition & 1 deletion dataserv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SQLALCHEMY_DATABASE_URI = "sqlite:///dataserv.db"

DATA_DIR = 'data/'
BYTE_SIZE = 1024*1024*128 # 128 MB
BYTE_SIZE = 1024*1024*128 # 128 MB FIXME rename, very confusing name
HEIGHT_LIMIT = 200000 # around 25 TB

ADDRESS = "16ZcxFDdkVJR1P8GMNmWFyhS4EKrRMsWNG" # unique per server address
Expand Down

0 comments on commit 67e6068

Please sign in to comment.