Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added/fixed/adjusted docstrings to be proper/consistent; Updated prin…
…t statements to follow 3.x convention; Added pydoc api documentation
- Loading branch information
1 parent
6242364
commit 7816703
Showing
2 changed files
with
366 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,219 @@ | |||
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | |||
<html><head><title>Python: module uploadr</title> | |||
</head><body bgcolor="#f0f0f8"> | |||
|
|||
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> | |||
<tr bgcolor="#7799ee"> | |||
<td valign=bottom> <br> | |||
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>uploadr</strong></big></big></font></td | |||
><td align=right valign=bottom | |||
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///F:/development/portablegit/uploadr.py/uploadr/uploadr.py">f:\development\portablegit\uploadr.py\uploadr\uploadr.py</a></font></td></tr></table> | |||
<p><tt>uploadr.py<br> | |||
<br> | |||
Upload images placed within a directory to your Flickr account.<br> | |||
<br> | |||
Requires:<br> | |||
xmltramp <a href="http://www.aaronsw.com/2002/xmltramp/">http://www.aaronsw.com/2002/xmltramp/</a><br> | |||
flickr account <a href="http://flickr.com">http://flickr.com</a><br> | |||
<br> | |||
Inspired by:<br> | |||
<a href="http://micampe.it/things/flickruploadr">http://micampe.it/things/flickruploadr</a><br> | |||
<br> | |||
Usage:<br> | |||
<br> | |||
The best way to use this is to just fire this up in the background and forget about it.<br> | |||
If you find you have CPU/Process limits, then setup a cron job.<br> | |||
<br> | |||
%nohup python uploadr.py -d &<br> | |||
<br> | |||
cron entry (runs at the top of every hour )<br> | |||
0 * * * * /full/path/to/uploadr.py > /dev/null 2>&1<br> | |||
<br> | |||
September 2005<br> | |||
Cameron Mallory cmallory/berserk.org<br> | |||
<br> | |||
This code has been updated to use the new Auth API from flickr.<br> | |||
<br> | |||
You may use this code however you see fit in any form whatsoever.</tt></p> | |||
<p> | |||
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |||
<tr bgcolor="#aa55cc"> | |||
<td colspan=3 valign=bottom> <br> | |||
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> | |||
|
|||
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> | |||
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="hashlib.html">hashlib</a><br> | |||
<a href="mimetools.html">mimetools</a><br> | |||
<a href="mimetypes.html">mimetypes</a><br> | |||
</td><td width="25%" valign=top><a href="os.html">os</a><br> | |||
<a href="shelve.html">shelve</a><br> | |||
<a href="string.html">string</a><br> | |||
</td><td width="25%" valign=top><a href="sys.html">sys</a><br> | |||
<a href="time.html">time</a><br> | |||
<a href="urllib2.html">urllib2</a><br> | |||
</td><td width="25%" valign=top><a href="webbrowser.html">webbrowser</a><br> | |||
<a href="xmltramp.html">xmltramp</a><br> | |||
</td></tr></table></td></tr></table><p> | |||
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |||
<tr bgcolor="#ee77aa"> | |||
<td colspan=3 valign=bottom> <br> | |||
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> | |||
|
|||
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> | |||
<td width="100%"><dl> | |||
<dt><font face="helvetica, arial"><a href="uploadr.html#APIConstants">APIConstants</a> | |||
</font></dt><dt><font face="helvetica, arial"><a href="uploadr.html#Uploadr">Uploadr</a> | |||
</font></dt></dl> | |||
<p> | |||
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |||
<tr bgcolor="#ffc8d8"> | |||
<td colspan=3 valign=bottom> <br> | |||
<font color="#000000" face="helvetica, arial"><a name="APIConstants">class <strong>APIConstants</strong></a></font></td></tr> | |||
|
|||
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> | |||
<td colspan=2><tt><a href="#APIConstants">APIConstants</a> class<br> </tt></td></tr> | |||
<tr><td> </td> | |||
<td width="100%">Methods defined here:<br> | |||
<dl><dt><a name="APIConstants-__init__"><strong>__init__</strong></a>(self)</dt><dd><tt>Constructor</tt></dd></dl> | |||
|
|||
<hr> | |||
Data and other attributes defined here:<br> | |||
<dl><dt><strong>auth</strong> = 'http://flickr.com/services/auth/'</dl> | |||
|
|||
<dl><dt><strong>base</strong> = 'http://flickr.com/services/'</dl> | |||
|
|||
<dl><dt><strong>frob</strong> = 'frob'</dl> | |||
|
|||
<dl><dt><strong>key</strong> = 'api_key'</dl> | |||
|
|||
<dl><dt><strong>method</strong> = 'method'</dl> | |||
|
|||
<dl><dt><strong>perms</strong> = 'perms'</dl> | |||
|
|||
<dl><dt><strong>rest</strong> = 'http://flickr.com/services/rest/'</dl> | |||
|
|||
<dl><dt><strong>secret</strong> = 'secret'</dl> | |||
|
|||
<dl><dt><strong>sig</strong> = 'api_sig'</dl> | |||
|
|||
<dl><dt><strong>token</strong> = 'auth_token'</dl> | |||
|
|||
<dl><dt><strong>upload</strong> = 'http://flickr.com/services/upload/'</dl> | |||
|
|||
</td></tr></table> <p> | |||
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |||
<tr bgcolor="#ffc8d8"> | |||
<td colspan=3 valign=bottom> <br> | |||
<font color="#000000" face="helvetica, arial"><a name="Uploadr">class <strong>Uploadr</strong></a></font></td></tr> | |||
|
|||
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> | |||
<td colspan=2><tt><a href="#Uploadr">Uploadr</a> class<br> </tt></td></tr> | |||
<tr><td> </td> | |||
<td width="100%">Methods defined here:<br> | |||
<dl><dt><a name="Uploadr-__init__"><strong>__init__</strong></a>(self)</dt><dd><tt>Constructor</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-authenticate"><strong>authenticate</strong></a>(self)</dt><dd><tt>Authenticate user so we can upload images</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-build_request"><strong>build_request</strong></a>(self, theurl, fields, files, txheaders<font color="#909090">=None</font>)</dt><dd><tt>build_request/encode_multipart_formdata code is from www.voidspace.org.uk/atlantibots/pythonutils.html<br> | |||
<br> | |||
Given the fields to set and the files to encode it returns a fully formed urllib2.Request object.<br> | |||
You can optionally pass in additional headers to encode into the opject. (Content-type and Content-length will be overridden if they are set).<br> | |||
fields is a sequence of (name, value) elements for regular form fields - or a dictionary.<br> | |||
files is a sequence of (name, filename, value) elements for data to be uploaded as files.</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-cacheToken"><strong>cacheToken</strong></a>(self)</dt><dd><tt>cacheToken</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-checkToken"><strong>checkToken</strong></a>(self)</dt><dd><tt>flickr.auth.checkToken<br> | |||
<br> | |||
Returns the credentials attached to an authentication token.<br> | |||
Authentication<br> | |||
<br> | |||
This method does not require authentication.<br> | |||
Arguments<br> | |||
<br> | |||
api.key (Required)<br> | |||
Your API application key. See here for more details.<br> | |||
auth_token (Required)<br> | |||
The authentication token to check.</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-encode_multipart_formdata"><strong>encode_multipart_formdata</strong></a>(self, fields, files, BOUNDARY<font color="#909090">='-----192.168.56.1.1.185220.1303072272.769.1-----'</font>)</dt><dd><tt>Encodes fields and files for uploading.<br> | |||
fields is a sequence of (name, value) elements for regular form fields - or a dictionary.<br> | |||
files is a sequence of (name, filename, value) elements for data to be uploaded as files.<br> | |||
Return (content_type, body) ready for urllib2.Request instance<br> | |||
You can optionally pass in a boundary string to use or we'll let mimetools provide one.</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-getAuthKey"><strong>getAuthKey</strong></a>(self)</dt><dd><tt>Checks to see if the user has authenticated this application</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-getCachedToken"><strong>getCachedToken</strong></a>(self)</dt><dd><tt>Attempts to get the flickr token from disk.</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-getFrob"><strong>getFrob</strong></a>(self)</dt><dd><tt>flickr.auth.getFrob<br> | |||
<br> | |||
Returns a frob to be used during authentication. This method call must be <br> | |||
signed.<br> | |||
<br> | |||
This method does not require authentication.<br> | |||
Arguments<br> | |||
<br> | |||
api.key (Required)<br> | |||
Your API application key. See here for more details.</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-getResponse"><strong>getResponse</strong></a>(self, url)</dt><dd><tt>Send the url and get a response. Let errors float up</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-getToken"><strong>getToken</strong></a>(self)</dt><dd><tt><a href="http://www.flickr.com/services/api/flickr.auth.getToken.html">http://www.flickr.com/services/api/flickr.auth.getToken.html</a><br> | |||
<br> | |||
flickr.auth.getToken<br> | |||
<br> | |||
Returns the auth token for the given frob, if one has been attached. This method call must be signed.<br> | |||
Authentication<br> | |||
<br> | |||
This method does not require authentication.<br> | |||
Arguments<br> | |||
<br> | |||
NTC: We need to store the token in a file so we can get it and then check it insted of<br> | |||
getting a new on all the time.<br> | |||
<br> | |||
api.key (Required)<br> | |||
Your API application key. See here for more details.<br> | |||
frob (Required)<br> | |||
The frob to check.</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-grabNewImages"><strong>grabNewImages</strong></a>(self)</dt><dd><tt>grabNewImages</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-isGood"><strong>isGood</strong></a>(self, res)</dt><dd><tt>isGood</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-logUpload"><strong>logUpload</strong></a>(self, photoID, imageName)</dt><dd><tt>logUpload</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-reportError"><strong>reportError</strong></a>(self, res)</dt><dd><tt>reportError</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-run"><strong>run</strong></a>(self)</dt><dd><tt>run</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-signCall"><strong>signCall</strong></a>(self, data)</dt><dd><tt>Signs args via md5 per <a href="http://www.flickr.com/services/api/auth.spec.html">http://www.flickr.com/services/api/auth.spec.html</a> (Section 8)</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-upload"><strong>upload</strong></a>(self)</dt><dd><tt>upload</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-uploadImage"><strong>uploadImage</strong></a>(self, image)</dt><dd><tt>uploadImage</tt></dd></dl> | |||
|
|||
<dl><dt><a name="Uploadr-urlGen"><strong>urlGen</strong></a>(self, base, data, sig)</dt><dd><tt>urlGen</tt></dd></dl> | |||
|
|||
<hr> | |||
Data and other attributes defined here:<br> | |||
<dl><dt><strong>TOKEN_FILE</strong> = '.flickrToken'</dl> | |||
|
|||
<dl><dt><strong>perms</strong> = ''</dl> | |||
|
|||
<dl><dt><strong>token</strong> = None</dl> | |||
|
|||
</td></tr></table></td></tr></table><p> | |||
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> | |||
<tr bgcolor="#55aa55"> | |||
<td colspan=3 valign=bottom> <br> | |||
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> | |||
|
|||
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> | |||
<td width="100%"><strong>FLICKR</strong> = {'api_key': 'test', 'description': '', 'is_family': '0', 'is_friend': '0', 'is_public': '1', 'secret': 'test', 'tags': 'auto-upload', 'title': ''}<br> | |||
<strong>HISTORY_FILE</strong> = 'uploadr.history'<br> | |||
<strong>IMAGE_DIR</strong> = 'images/'<br> | |||
<strong>SLEEP_TIME</strong> = 60<br> | |||
<strong>api</strong> = <uploadr.APIConstants instance></td></tr></table> | |||
</body></html> |
Oops, something went wrong.