Skip to content

Instantly share code, notes, and snippets.

@jeandersonbc
Last active November 28, 2016 18:27
Show Gist options
  • Save jeandersonbc/ca807f8b1b29a1f191cc6d9f6b16ca25 to your computer and use it in GitHub Desktop.
Save jeandersonbc/ca807f8b1b29a1f191cc6d9f6b16ca25 to your computer and use it in GitHub Desktop.
Get Github issues with Python
#!/usr/bin/env python3
#
# Author: Jeanderson Candido
import json
import urllib.request
from io import StringIO
# INPUT PARAMETERS:
# - OWNER: Repository owner
# - PROJECT: Target repository
OWNER = "octocat"
PROJECT = "Hello-World"
# By default, the API returns only OPEN ISSUES. I added the param "state=all" to
# include CLOSED ISSUES as well. I use STRING FORMATTING to make easier to create
# URLS with different pages. Take a look at https://docs.python.org/3/library/string.html#format-examples
# for more information
URL_ENDPOINT = "https://api.github.com/repos/{OWNER}/{PROJECT}/issues" \
"?state=all&per_page=100&page={PAGE}"
CSV_OUTPUT_PATH = "{}-{}-issues.csv".format(OWNER, PROJECT)
with open(CSV_OUTPUT_PATH, "w", newline="") as fin:
fin.write("title,url\n")
# Here, we do a loop to make an HTTP request with a different page
page=1
while True:
URL=URL_ENDPOINT.format(OWNER=OWNER, PROJECT=PROJECT, PAGE=page)
print(URL)
# Make an HTTP REQUEST to the URL
# Ref: https://docs.python.org/3/howto/urllib2.html
try:
with urllib.request.urlopen(URL) as response:
json_data = json.load(StringIO(response.read().decode()))
for js in json_data:
with open(CSV_OUTPUT_PATH, "a", newline="") as fin:
fin.write(",".join([js["title"], js["html_url"]]))
fin.write("\n")
except urllib.request.HTTPError as err:
print("Aborting due to {}".format(err))
exit(1)
# increment page
page += 1
title,url
This is a test-issue,https://github.com/octocat/Hello-World/issues/269
Update README,https://github.com/octocat/Hello-World/pull/268
update readme,https://github.com/octocat/Hello-World/pull/267
Update README,https://github.com/octocat/Hello-World/pull/266
An empty repository with 1,4k+ Stars - WOW,https://github.com/octocat/Hello-World/issues/262
Update README,https://github.com/octocat/Hello-World/pull/261
Hello-world,https://github.com/octocat/Hello-World/issues/260
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/259
CO-mitting a new file,https://github.com/octocat/Hello-World/pull/258
Test api issue,https://github.com/octocat/Hello-World/issues/257
Found a bug,https://github.com/octocat/Hello-World/issues/256
Contributors add,https://github.com/octocat/Hello-World/pull/255
add new fix hello file,https://github.com/octocat/Hello-World/pull/254
Hotfix,https://github.com/octocat/Hello-World/pull/253
Just a test,https://github.com/octocat/Hello-World/issues/252
20160601_test,https://github.com/octocat/Hello-World/issues/251
Added new file,https://github.com/octocat/Hello-World/pull/250
test,https://github.com/octocat/Hello-World/issues/249
Test,https://github.com/octocat/Hello-World/pull/248
Added file, edited readme.,https://github.com/octocat/Hello-World/pull/247
Tesing,https://github.com/octocat/Hello-World/issues/246
Test,https://github.com/octocat/Hello-World/pull/245
test 123,https://github.com/octocat/Hello-World/issues/244
test,https://github.com/octocat/Hello-World/pull/243
issue test,https://github.com/octocat/Hello-World/issues/242
Testing,https://github.com/octocat/Hello-World/issues/241
Found a bug,https://github.com/octocat/Hello-World/issues/240
Changes made,https://github.com/octocat/Hello-World/pull/239
Update some text by flyquan...,https://github.com/octocat/Hello-World/pull/238
Making another with another readme,https://github.com/octocat/Hello-World/pull/237
Added my name to README,https://github.com/octocat/Hello-World/pull/236
Found a bug,https://github.com/octocat/Hello-World/issues/235
Found a bug,https://github.com/octocat/Hello-World/issues/234
Found a bug,https://github.com/octocat/Hello-World/issues/233
Found a bug,https://github.com/octocat/Hello-World/issues/232
Found a bug,https://github.com/octocat/Hello-World/issues/231
Found a bug,https://github.com/octocat/Hello-World/issues/230
Create new file,https://github.com/octocat/Hello-World/pull/229
NewBie,https://github.com/octocat/Hello-World/pull/228
Update README,https://github.com/octocat/Hello-World/pull/227
Update README,https://github.com/octocat/Hello-World/pull/226
Create Hello world,https://github.com/octocat/Hello-World/pull/225
Create Hello world,https://github.com/octocat/Hello-World/pull/224
test to create a pull request,https://github.com/octocat/Hello-World/pull/223
Testing another pull request,https://github.com/octocat/Hello-World/pull/222
This is a test,https://github.com/octocat/Hello-World/pull/221
Found a bug,https://github.com/octocat/Hello-World/issues/220
Found a bug,https://github.com/octocat/Hello-World/issues/219
Found a bug,https://github.com/octocat/Hello-World/issues/218
Testing pull requests,https://github.com/octocat/Hello-World/pull/217
test,https://github.com/octocat/Hello-World/issues/216
Found a bug,https://github.com/octocat/Hello-World/issues/215
Create lol.txt,https://github.com/octocat/Hello-World/pull/214
Found a bug,https://github.com/octocat/Hello-World/issues/213
Found a bug,https://github.com/octocat/Hello-World/issues/212
Found a bug,https://github.com/octocat/Hello-World/issues/211
Found a bug,https://github.com/octocat/Hello-World/issues/210
Foo Bar - The Ultimate Coffee Bar for Programmers!,https://github.com/octocat/Hello-World/issues/209
Update README,https://github.com/octocat/Hello-World/pull/208
Java - postgresSQl - Elasticsearch ,https://github.com/octocat/Hello-World/issues/197
Master1,https://github.com/octocat/Hello-World/pull/196
Bai-World v2.0,https://github.com/octocat/Hello-World/pull/195
Am 01,https://github.com/octocat/Hello-World/pull/194
Am 01,https://github.com/octocat/Hello-World/pull/193
Readme modified,https://github.com/octocat/Hello-World/pull/192
foobar,https://github.com/octocat/Hello-World/issues/191
This is a test commit to see if I am able to upload files,https://github.com/octocat/Hello-World/pull/189
Small updates to Readme documenting functions,https://github.com/octocat/Hello-World/pull/188
adiputra88,https://github.com/octocat/Hello-World/issues/187
Hello World,https://github.com/octocat/Hello-World/issues/186
indonesia,https://github.com/octocat/Hello-World/issues/185
Revert "New line at end of file.",https://github.com/octocat/Hello-World/pull/184
Help,https://github.com/octocat/Hello-World/issues/183
Newbranch,https://github.com/octocat/Hello-World/pull/182
Testing an issue,https://github.com/octocat/Hello-World/issues/181
Testing Editing,https://github.com/octocat/Hello-World/pull/180
test pull request for hello-world,https://github.com/octocat/Hello-World/issues/179
Update README,https://github.com/octocat/Hello-World/pull/178
Update README,https://github.com/octocat/Hello-World/pull/177
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/176
Create test-file.txt,https://github.com/octocat/Hello-World/pull/175
Issue test,https://github.com/octocat/Hello-World/issues/174
Update README,https://github.com/octocat/Hello-World/pull/173
mede,https://github.com/octocat/Hello-World/issues/172
this is to test,https://github.com/octocat/Hello-World/issues/171
change readme,https://github.com/octocat/Hello-World/pull/170
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/169
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/168
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/167
Found a bug,https://github.com/octocat/Hello-World/issues/166
made small changes to the readme file,https://github.com/octocat/Hello-World/pull/165
Checked UTF-8 support,https://github.com/octocat/Hello-World/pull/164
Update README,https://github.com/octocat/Hello-World/pull/163
hello,https://github.com/octocat/Hello-World/issues/162
Octocat is too overpowered,https://github.com/octocat/Hello-World/issues/161
holy,https://github.com/octocat/Hello-World/issues/160
My branch,https://github.com/octocat/Hello-World/pull/159
Update and rename README to README.md. Also Added Bolding,https://github.com/octocat/Hello-World/pull/158
adobe reader,https://github.com/octocat/Hello-World/issues/157
demonstration purposes,https://github.com/octocat/Hello-World/pull/156
Can't download,https://github.com/octocat/Hello-World/issues/155
Found a bug,https://github.com/octocat/Hello-World/issues/154
Can't read!,https://github.com/octocat/Hello-World/issues/153
Update README,https://github.com/octocat/Hello-World/pull/152
For Test (Jarvin_G),https://github.com/octocat/Hello-World/pull/151
Update README,https://github.com/octocat/Hello-World/pull/150
Create index.html,https://github.com/octocat/Hello-World/pull/149
issue title,https://github.com/octocat/Hello-World/issues/148
issue title,https://github.com/octocat/Hello-World/issues/147
issue title,https://github.com/octocat/Hello-World/issues/146
issue title,https://github.com/octocat/Hello-World/issues/145
issue title,https://github.com/octocat/Hello-World/issues/144
issue title,https://github.com/octocat/Hello-World/issues/143
issue title,https://github.com/octocat/Hello-World/issues/142
changed text,https://github.com/octocat/Hello-World/pull/141
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/140
Create github hello world,https://github.com/octocat/Hello-World/pull/139
Create CONTRIBUTING.md,https://github.com/octocat/Hello-World/pull/138
I have no clue about this,https://github.com/octocat/Hello-World/issues/137
Added Perl Implementation,https://github.com/octocat/Hello-World/pull/136
Create help,https://github.com/octocat/Hello-World/pull/135
TheWhiteLord5,https://github.com/octocat/Hello-World/pull/134
Signed-off-by: lighter <haojingjing.hjj@gmail.com>,https://github.com/octocat/Hello-World/pull/133
Update README,https://github.com/octocat/Hello-World/pull/132
Update README,https://github.com/octocat/Hello-World/pull/131
Delete README,https://github.com/octocat/Hello-World/pull/130
test,https://github.com/octocat/Hello-World/pull/129
Found a bug,https://github.com/octocat/Hello-World/issues/128
Other choices!,https://github.com/octocat/Hello-World/pull/127
Added a cpp file,https://github.com/octocat/Hello-World/pull/126
test,https://github.com/octocat/Hello-World/pull/125
Spanish,https://github.com/octocat/Hello-World/pull/123
before update,https://github.com/octocat/Hello-World/pull/122
Create helloworld.cpp,https://github.com/octocat/Hello-World/pull/121
added fish,https://github.com/octocat/Hello-World/pull/120
Testing,https://github.com/octocat/Hello-World/pull/119
GSoC,https://github.com/octocat/Hello-World/issues/118
Zeile hinzugefügt,https://github.com/octocat/Hello-World/pull/117
New issue,https://github.com/octocat/Hello-World/issues/116
Added a new line,https://github.com/octocat/Hello-World/pull/115
Patch 1,https://github.com/octocat/Hello-World/pull/114
Update README,https://github.com/octocat/Hello-World/pull/113
Update README,https://github.com/octocat/Hello-World/pull/112
what is hello without a smile,https://github.com/octocat/Hello-World/pull/111
Create manifest.webapp,https://github.com/octocat/Hello-World/pull/110
testfile,https://github.com/octocat/Hello-World/pull/109
added "test" to readme,https://github.com/octocat/Hello-World/pull/108
Add !!,https://github.com/octocat/Hello-World/pull/107
Wise title,https://github.com/octocat/Hello-World/pull/106
Update README,https://github.com/octocat/Hello-World/pull/105
README Tutorial,https://github.com/octocat/Hello-World/issues/104
Update README,https://github.com/octocat/Hello-World/pull/103
the first of many,https://github.com/octocat/Hello-World/pull/102
Update README,https://github.com/octocat/Hello-World/pull/101
Update README,https://github.com/octocat/Hello-World/pull/100
Update README,https://github.com/octocat/Hello-World/pull/99
testing,https://github.com/octocat/Hello-World/issues/98
Testing!,https://github.com/octocat/Hello-World/issues/97
More language for hello!,https://github.com/octocat/Hello-World/pull/96
Update README,https://github.com/octocat/Hello-World/pull/94
ajax.inc.php,https://github.com/octocat/Hello-World/pull/93
Update README,https://github.com/octocat/Hello-World/pull/92
Update README,https://github.com/octocat/Hello-World/pull/91
Update README,https://github.com/octocat/Hello-World/pull/90
add printf(),https://github.com/octocat/Hello-World/pull/89
edited readme,https://github.com/octocat/Hello-World/pull/88
Update README,https://github.com/octocat/Hello-World/pull/87
Update README,https://github.com/octocat/Hello-World/pull/86
How to create a comment?,https://github.com/octocat/Hello-World/issues/85
Pull R test 1,https://github.com/octocat/Hello-World/pull/84
Pull Request test,https://github.com/octocat/Hello-World/pull/83
Slave,https://github.com/octocat/Hello-World/pull/82
Found a bug,https://github.com/octocat/Hello-World/issues/81
Traducción española,https://github.com/octocat/Hello-World/pull/80
Hello World Test,https://github.com/octocat/Hello-World/pull/79
Found a bug,https://github.com/octocat/Hello-World/issues/78
Created Hello World!,https://github.com/octocat/Hello-World/pull/77
Merge:Just an addition,https://github.com/octocat/Hello-World/pull/76
Update README,https://github.com/octocat/Hello-World/pull/75
Update README,https://github.com/octocat/Hello-World/pull/74
test!,https://github.com/octocat/Hello-World/pull/73
Update README,https://github.com/octocat/Hello-World/pull/72
Added hello world in Arabic and Tamil languages!,https://github.com/octocat/Hello-World/pull/71
test pull request,https://github.com/octocat/Hello-World/pull/70
TestIssue,https://github.com/octocat/Hello-World/issues/69
my request,https://github.com/octocat/Hello-World/pull/68
Update README,https://github.com/octocat/Hello-World/pull/67
Update README,https://github.com/octocat/Hello-World/pull/66
Update README,https://github.com/octocat/Hello-World/pull/65
test update readme,https://github.com/octocat/Hello-World/issues/64
try to test be social,https://github.com/octocat/Hello-World/pull/63
Update README,https://github.com/octocat/Hello-World/pull/62
Update README,https://github.com/octocat/Hello-World/pull/61
Testing a pull request,https://github.com/octocat/Hello-World/pull/60
Update README,https://github.com/octocat/Hello-World/pull/59
Update README,https://github.com/octocat/Hello-World/pull/58
Update README----,https://github.com/octocat/Hello-World/pull/57
do a littel change,https://github.com/octocat/Hello-World/pull/56
Found a bug,https://github.com/octocat/Hello-World/issues/55
Found a bug,https://github.com/octocat/Hello-World/issues/54
Found a bug,https://github.com/octocat/Hello-World/issues/53
Found a bug,https://github.com/octocat/Hello-World/issues/52
Test,https://github.com/octocat/Hello-World/issues/51
this is a test,https://github.com/octocat/Hello-World/issues/50
Just a test,https://github.com/octocat/Hello-World/issues/49
Added comma.,https://github.com/octocat/Hello-World/pull/48
a new one ,https://github.com/octocat/Hello-World/issues/47
Update README,https://github.com/octocat/Hello-World/pull/46
Found a bug,https://github.com/octocat/Hello-World/issues/45
Found a bug,https://github.com/octocat/Hello-World/issues/44
Found a bug,https://github.com/octocat/Hello-World/issues/43
Found a bug,https://github.com/octocat/Hello-World/issues/42
repo.git issue,https://github.com/octocat/Hello-World/issues/41
test,https://github.com/octocat/Hello-World/pull/40
Update master,https://github.com/octocat/Hello-World/pull/39
Just another instance of the species is invaded by the wonder he can fee...,https://github.com/octocat/Hello-World/pull/38
Update master,https://github.com/octocat/Hello-World/pull/37
Second Hello World added to README,https://github.com/octocat/Hello-World/pull/36
Update README,https://github.com/octocat/Hello-World/pull/35
Just a pull request test,https://github.com/octocat/Hello-World/pull/34
It's just a test!,https://github.com/octocat/Hello-World/pull/33
Update README,https://github.com/octocat/Hello-World/pull/32
test,https://github.com/octocat/Hello-World/issues/31
another test,https://github.com/octocat/Hello-World/issues/30
test,https://github.com/octocat/Hello-World/issues/29
Test,https://github.com/octocat/Hello-World/issues/28
just for test,https://github.com/octocat/Hello-World/issues/27
test issue,https://github.com/octocat/Hello-World/issues/26
Test,https://github.com/octocat/Hello-World/issues/25
test issue,https://github.com/octocat/Hello-World/issues/24
Added !!!,https://github.com/octocat/Hello-World/pull/23
Tim test Fiddler title,https://github.com/octocat/Hello-World/issues/22
Tim test title,https://github.com/octocat/Hello-World/issues/21
Admin pages don't render in IE10 via Fiddler w text/plain,https://github.com/octocat/Hello-World/issues/20
Admin pages don't render in IE10 via Fiddler,https://github.com/octocat/Hello-World/issues/19
Admin pages don't render in IE10,https://github.com/octocat/Hello-World/issues/18
Admin pages dont render in IE10,https://github.com/octocat/Hello-World/issues/17
creating an issue,https://github.com/octocat/Hello-World/issues/16
creating an issue,https://github.com/octocat/Hello-World/issues/15
creating an issue,https://github.com/octocat/Hello-World/issues/14
Test Issue Log,https://github.com/octocat/Hello-World/issues/13
Test,https://github.com/octocat/Hello-World/issues/12
test100,https://github.com/octocat/Hello-World/issues/11
test100,https://github.com/octocat/Hello-World/issues/10
test,https://github.com/octocat/Hello-World/pull/9
chck,https://github.com/octocat/Hello-World/pull/8
Hello World in all programming languages,https://github.com/octocat/Hello-World/issues/7
New line at end of file.,https://github.com/octocat/Hello-World/pull/6
tst,https://github.com/octocat/Hello-World/pull/5
test title,https://github.com/octocat/Hello-World/pull/4
Edited README via GitHub,https://github.com/octocat/Hello-World/pull/3
README file modified ,https://github.com/octocat/Hello-World/pull/2
Edited README via GitHub,https://github.com/octocat/Hello-World/pull/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment