Skip to content

Instantly share code, notes, and snippets.

@rawsh
Created January 12, 2017 20:10
Show Gist options
  • Save rawsh/98503959455031a65ec7dad083748c80 to your computer and use it in GitHub Desktop.
Save rawsh/98503959455031a65ec7dad083748c80 to your computer and use it in GitHub Desktop.
Dads code
#!/usr/bin/env python2
from oauth2client.client import OAuth2WebServerFlow
import gdata.photos.service
import os
print "Content-type: text/html"
print
print "<title>Google Photos Browser</title>"
flow = OAuth2WebServerFlow(client_id='231197837344-skdbuop575r1f55cm9u1v839ph6oc0dd.apps.googleusercontent.com',
client_secret='--l0NnAmQN1pZBBcWX9WV-BC',
scope='https://picasaweb.google.com/data/',
redirect_uri='http://localhost/albums.py')
query = os.environ.get("QUERY_STRING", "None")
if query.split("=")[0] == "code":
credentials = flow.step2_exchange(query.split("=")[1])
gd_client = gdata.photos.service.PhotosService(additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token})
albums = gd_client.GetUserFeed()
for album in albums.entry:
print '<p>%s (%s)</p>' % (album.title.text,album.numphotos.text)
photos = gd_client.GetFeed(
'/data/feed/api/user/%s/albumid/%s?kind=photo' % (
"rawashbourne", album.gphoto_id.text))
for photo in photos.entry:
print '<pre>&#60;img src="%s" alt="%s"&#62;&#60;/img&#62;</pre>' % (
photo.content.src, photo.title.text)
else:
auth_uri = flow.step1_get_authorize_url()
print "<a href="+auth_uri+">authorize the program</a>"
#!/usr/bin/env python2
import BaseHTTPServer
import CGIHTTPServer
import cgitb
cgitb.enable() # This line enables CGI error reporting
server = BaseHTTPServer.HTTPServer
class customHandler(CGIHTTPServer.CGIHTTPRequestHandler):
def do_GEsdT( self ):
self.send_response(200)
self.send_header( 'Content-type', 'text/html' )
self.end_headers()
self.wfile.write( open('index.html').read() )
handler = customHandler
server_address = ("", 80)
handler.cgi_directories = ["/"]
httpd = server(server_address, handler)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment