Skip to content

Instantly share code, notes, and snippets.

@auwsome
Created August 24, 2015 16:25
Show Gist options
  • Save auwsome/3304addbdf05c34d372b to your computer and use it in GitHub Desktop.
Save auwsome/3304addbdf05c34d372b to your computer and use it in GitHub Desktop.
Get and read file from Github and save as file
import os, urllib2
realcwd = os.path.dirname(os.path.realpath(__file__))
url1 = 'http://raw.githubusercontent.com/auwsome/pybot/master/Pybot.py'
#urls[1] = 'http://raw.githubusercontent.com/auwsome/pybot/master/sendPybot.py'
#for url in urls[url]:
req = urllib2.Request(url1)
response = urllib2.urlopen(req)
# print response.getcode()
# print response.headers.getheader('content-type
try:
response = urllib2.urlopen(req)
except urllib2.HTTPError, e:
print('HTTP Error', e)
res = e.fp.read()
#return json.loads(res), str(e) # for use as function
page = response.read()
#print json.loads(res)
outfile = os.path.join(realcwd,'Pybot.py')
with open(outfile, 'w') as file:
file.write(page)
print outfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment