Skip to content

Commit

Permalink
samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Dec 13, 2020
1 parent 1ed7c34 commit 36a1799
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sample_evts.json.gz
*test.*
conda/
.sass-cache/
Expand Down
11 changes: 8 additions & 3 deletions 04_event.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"from ghapi.core import *\n",
"from ghapi.page import *\n",
"\n",
"import time\n",
"import time,json,gzip\n",
"from itertools import islice"
]
},
Expand Down Expand Up @@ -181,7 +181,13 @@
"#export\n",
"def load_sample_events():\n",
" \"Load sample events, downloading if needed\"\n",
" return dict2obj(json.load(open_file('sample_evts.json.gz')))"
" name = 'sample_evts.json.gz'\n",
" url = f'https://raw.githubusercontent.com/fastai/ghapi/master/examples/{name}'\n",
" try: path = Path(__file__).parent\n",
" except NameError: path = Path()/'examples'\n",
" path = path/name\n",
" if not path.exists(): path.write_bytes(urlread(url, decode=False))\n",
" return dict2obj(json.load(open_file(path)))"
]
},
{
Expand All @@ -193,7 +199,6 @@
"#export\n",
"def save_sample_events(n=1000):\n",
" \"Save the most recent `n` events as compressed JSON\"\n",
" import json,gzip\n",
" evts = list(islice(api.fetch_events(incl_bot=True), 1000))\n",
" with gzip.open('sample_evts.json.gz', 'wt') as f: json.dump(obj2dict(evts), f)"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ <h4 id="load_sample_events" class="doc_header"><code>load_sample_events</code><a


<div class="output_markdown rendered_html output_subarea ">
<h4 id="save_sample_events" class="doc_header"><code>save_sample_events</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/event.py#L73" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>save_sample_events</code>(<strong><code>n</code></strong>=<em><code>1000</code></em>)</p>
<h4 id="save_sample_events" class="doc_header"><code>save_sample_events</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/event.py#L79" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>save_sample_events</code>(<strong><code>n</code></strong>=<em><code>1000</code></em>)</p>
</blockquote>
<p>Save the most recent <code>n</code> events as compressed JSON</p>

Expand Down
11 changes: 8 additions & 3 deletions ghapi/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .core import *
from .page import *

import time
import time,json,gzip
from itertools import islice

# Cell
Expand Down Expand Up @@ -67,11 +67,16 @@ def fetch_events(self:GhApi, n_pages=3, pause=0.4, per_page=30, types=None, incl
# Cell
def load_sample_events():
"Load sample events, downloading if needed"
return dict2obj(json.load(open_file('sample_evts.json.gz')))
name = 'sample_evts.json.gz'
url = f'https://raw.githubusercontent.com/fastai/ghapi/master/examples/{name}'
try: path = Path(__file__).parent
except NameError: path = Path()/'examples'
path = path/name
if not path.exists(): path.write_bytes(urlread(url, decode=False))
return dict2obj(json.load(open_file(path)))

# Cell
def save_sample_events(n=1000):
"Save the most recent `n` events as compressed JSON"
import json,gzip
evts = list(islice(api.fetch_events(incl_bot=True), 1000))
with gzip.open('sample_evts.json.gz', 'wt') as f: json.dump(obj2dict(evts), f)

0 comments on commit 36a1799

Please sign in to comment.