Skip to content

Instantly share code, notes, and snippets.

@corpix
Created September 27, 2015 12:12
Show Gist options
  • Save corpix/8fdf9ca481da3004714c to your computer and use it in GitHub Desktop.
Save corpix/8fdf9ca481da3004714c to your computer and use it in GitHub Desktop.
heroku logsaver
# -*- coding: utf-8 -*-
from __future__ import print_function
import requests
from lxml import html
import json
import sys
import os
HOST = "http://lumber.leanpoker.org"
SOURCE = HOST + "/logs/tournament/55e4be2d4adaaf0003000002/team/poker-player-abuse-or-lose/log"
r = requests.get(SOURCE)
text = r.text
tree = html.fromstring(text)
uris = []
for a in tree.xpath('//a'):
uri = a.get("href")
if uri and len(uri):
uris.append(HOST + uri)
for uri in reversed(uris):
name = os.path.basename(uri)
if not os.path.exists(name):
print("#getting", name)
with open(name, "w+") as fd:
fd.write(requests.get(uri).text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment