Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
add HPT json to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankicks committed May 27, 2015
1 parent 7a5a63d commit 160cefb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
26 changes: 24 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def get(self, id):
response = Utils.get_bq().tables().get(projectId=project, datasetId=dataset, tableId=table).execute()

created = float(response['creationTime'])
response['creationTime'] = Utils.millis_to_date(created)
response['creationTime'] = Utils.millis_to_str(created)

updated = float(response['lastModifiedTime'])
response['lastModifiedTime'] = Utils.millis_to_date(updated)
response['lastModifiedTime'] = Utils.millis_to_str(updated)

self.response.out.write(JINJA.get_template('table_detail.html').render(response))

Expand All @@ -212,11 +212,33 @@ def get(self):

response = rules.get_rules(**GNIP_RULES_PARAMS)

FORMAT = "%Y%m%d%H%M"
end = datetime.now()

# scope by table
if table:

(project, dataset, table) = Utils.parse_bqid(table)
tag = Utils.make_tag(dataset, table)
response = [r for r in response if r['tag'] == tag]

table = Utils.get_bq().tables().get(projectId=project, datasetId=dataset, tableId=table).execute()

end = float(table['creationTime'])
end = Utils.millis_to_date(end)

start = end - timedelta(days=SEARCH_DAYS)

for r in response:
tag = r['tag']
r['hpt'] = json.dumps({
"publisher": "twitter",
"streamType": "track",
"dataFormat": "activity-streams",
"fromDate": start.strftime(FORMAT),
"toDate": end.strftime(FORMAT),
"rules": [{"tag": tag, "value": r['value']}], "title": tag})

self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(response))

Expand Down
6 changes: 5 additions & 1 deletion templates/table_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1>
<div class="col-md-2"><label>Updated</label></div>
<div class="col-md-4">{{lastModifiedTime}}</div>
</div>

<br>

<!-- Nav tabs -->
Expand All @@ -50,6 +50,7 @@ <h1>
<tr>
<th>Rule</th>
<th>Dataset</th>
<th width="40%">HPT JSON</th>
<th>Actions</th>
</tr>
</thead>
Expand Down Expand Up @@ -80,6 +81,9 @@ <h1>
<td>
{{tag}}
</td>
<td>
{{hpt}}
</td>
<td>
<a class="rule_backfill" data-rule="{{value}}" data-table="{{tag}}">backfill</a>
|
Expand Down
8 changes: 6 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,14 @@ def convert_timestamp(str):
ts = time.strftime('%Y-%m-%d %H:%M:%S', ts)

return ts

@staticmethod
def millis_to_date(ts):
return datetime.fromtimestamp(ts/1000).strftime('%Y-%m-%d %H:%M')
return datetime.fromtimestamp(ts/1000)

@staticmethod
def millis_to_str(ts, format='%Y-%m-%d %H:%M'):
return Utils.millis_to_date(ts).strftime(format)

@staticmethod
def parse_bqid(id):
Expand Down

0 comments on commit 160cefb

Please sign in to comment.