forums
new posts
donate
UER Store
events
location db
db map
search
members
faq
terms of service
privacy policy
register
login




UER Forum > Private Boards Index > Tech Talk > Photo posting script (Viewed 1644 times)
makman 


Location: Rochester, NY
Gender: Male
Total Likes: 0 likes


I live alone with a criminal

 |  | 
Photo posting script
< on 6/20/2010 4:11 PM >
Reply with Quote
Posted on Forum: UER Forum
So, my usual workflow for posting photos here is:
1) Upload to Flickr as a set
2) Go through each photo and
2.1) Copy the image url
2.2) Paste into a thread as [eimg]http://flickr.com/whatever/123.jpg[/eimg]
3) Preview the page, and go resize each image using the [img=100,200][/img]syntax
4) Post

So, being the lazy bum I am, I threw together a little python script last night to do this for me. It's a really rough, prototypical thing, and has 0 error handling, but it works. You give it a username, a flickr set name, a maximum width, and tell it whether you want your [eimg]s wrapped in [url]s, and it gives you back a list like:

[url=http://farm5.static.flickr.com/4016/4715644312_d89d761d28_o.jpg][img=600,399]http://far m5.static.flickr.com/4016/4715644312_4c2f54aaf0_b.jpg[/eimg][/url]

[url=http://farm5.static.flickr .com/4050/4715645728_65dd74afd7_o.jpg][img=600,399]http://farm5.static.flickr.com/4050/4715645728_81f 98aeeaf_b.jpg[/img][/url]

[url=http://farm5.static.flickr.com/4070/4715667292_78133ac8be_o.jpg][im g=600,787]http://farm5.static.flickr.com/4070/4715667292_f3ec582760_b.jpg[/img][/url]

Anyway, all you need is Python and this guy's python flickr kit. I'm planning to eventually clean it up and give it a web interface at some point (right now the UI is just editing the variables in the script), but I figured people here might find it useful as it is if they're able to intall a python module and run a python program. Script:

import flickrapi

userName="macman5151"
setName="Summer Camp"
targetSize="Large"
maxWidth = 600;
makeLinks = False;

def formatToPrint(source,url,width,height):
newHeight=height
newWidth=width
if(maxWidth<width):
newHeight = int(height * ((1.0*maxWidth)/(width)))
newWidth = int(maxWidth)
img = "[img="+str(newWidth)+","+str(newHeight)+"]"+source+"[/img]"
result = "[url="+url+"]"+img+"[/url]"
return result if makeLinks else img

api_key = '7c0d60047e1d56575439268441bfcb26'
flickr = flickrapi.FlickrAPI(api_key)

userTree = flickr.people_findByUsername(username=userName)
userId = userTree.getchildren()[0].attrib['nsid']
setTree = flickr.photosets_getList(user_id=userId)
photosets = setTree.getchildren()[0].getchildren()

setId = -1;
for photoset in photosets:
title = photoset.find('title').text
if(setName==title):
setId = photoset.attrib['id']
break

photoset = flickr.photosets_getPhotos(photoset_id=setId).getchildren()[0]
height=-1
width=-1
url = ''
for photo in photoset.getchildren():
id = photo.attrib['id']
sizes = flickr.photos_getSizes(photo_id=id).getchildren()[0]
for size in sizes:
if(size.attrib['label']==targetSize):
width = int(size.attrib['width'])
height = int(size.attrib['height'])
source = size.attrib['source']
if(size.attrib['label']=='Original'):
url = size.attrib['source']
print formatToPrint(source,url,width,height)




Be careful, not safe.

"Urbex- so much fun that it should be illegal."
trent 

I'm Trent! Get Bent!


Location: Drainwhale hunting
Gender: Male
Total Likes: 9 likes


Not on UER anymore.

 |  |  | infinitedecay
Re: Photo posting script
< Reply # 1 on 6/21/2010 5:50 PM >
Reply with Quote
Posted on Forum: UER Forum
Interesting. I might geek out with this later on this summer when I have time.




He who rules the underground, rules the city above.
UER Forum > Private Boards Index > Tech Talk > Photo posting script (Viewed 1644 times)


Add a poll to this thread



This thread is in a public category, and can't be made private.



All content and images copyright © 2002-2024 UER.CA and respective creators. Graphical Design by Crossfire.
To contact webmaster, or click to email with problems or other questions about this site: UER CONTACT
View Terms of Service | View Privacy Policy | Server colocation provided by Beanfield
This page was generated for you in 58 milliseconds. Since June 23, 2002, a total of 738497334 pages have been generated.