#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime, xmlrpclib, os,re,Image, shutil
wp_username = "crepuscule"
wp_password = "iiiiiiiiiiiiiiiiiie"
# Variables you probably don't have to change
wp_url = "http://ramen.kanojo.de/wordpress/xmlrpc.php"
wp_blogid = "12"
status_draft = 1
status_published = 0
tmpdir = "ramen_tmp"
categories = ["Review"]
date_created = xmlrpclib.DateTime(datetime.datetime.today())
tags = []
th_maxsize = 550
# START OF SCRIPT
print "Welcome to the Ramenprogramm Upload script\n\nPictures you want to upload have to be in the current working directory.\nTHE FIRST PICTURE THAT MATCHES WILL BE THE HEADER PICTURE.\nPlease make sure all pictures are rotated correctly. Only exifautotran will be called.\n"
startvalue = raw_input("Startwert XXXXXXXX :")
picturecount = raw_input("Anzahl YY :")
server = xmlrpclib.ServerProxy(wp_url)
title = "%s next review draft [title pending]"%wp_username
# Prepare picture
fStruct = {}
fStruct['type'] = 'image/jpeg'
allfiles = os.listdir(os.getcwd())
allfiles.sort()
barcodefound = False
imagelist = []
for i in range(0, int(picturecount)):
value = str(int(startvalue) + i)
imagename = value+".JPG"
while len(imagename) < 12:
imagename = "0"+imagename
tmpimagename = "tmp"+imagename
imagelist.append(tmpimagename)
print "Processing Image %s"%imagename
os.system("convert -resize 1000x1000 %s %s"%(imagename,tmpimagename))
os.system("exifautotran %s"%imagename)
if barcodefound == False:
f = os.popen("zbarimg -q --raw %s"%imagename)
barcode = f.readline().rstrip()
if f.close() == None:
print "Barcode detected"
barcodefound = True
if barcodefound == False:
barcode = raw_input("No barcode found. Switching to manual input :")
os.system("barcode -b %s -e ean-13 | convert -gravity SouthWest -crop 125x100+0+0 - barcode.JPG"%barcode)
imagelist.append("barcode.JPG")
print "Uploading pictures"
uploadurls = []
for filename in imagelist:
fStruct['name'] = filename
path = filename
print path
handle = open(path, 'rb')
data = handle.read()
handle.close()
fStruct['bits'] = xmlrpclib.Binary(data)
imageurl = server.metaWeblog.newMediaObject(wp_blogid, wp_username, wp_password, fStruct)['url']
size = Image.open(path).size
ratio = 1
width = size[0]
height = size[1]
ratio = float(th_maxsize)/float(max(width,height))
if not (width<=th_maxsize and height<=th_maxsize):
suffix = "-%sx%s"%(int(width*ratio),int(height*ratio))
imageurl = re.sub(".jpg","%s.jpg"%suffix,imageurl,re.IGNORECASE)
imageurl = re.sub("http://www.xn--nd-xka.li","..",imageurl,re.IGNORECASE)
uploadurls.append(imageurl)
os.remove(filename)
print "Done."
imagestring = ""
for i in uploadurls[1:-1]:
imagestring += "\n"%i
content = "
| Hersteller | |
| Geschmacksrichtung | |
| Preis | Eur |
| Inhalt |
|
| Portionen | 1 |
| Gewicht | g |
| Nudelart | |
| Geschmacks- übereinstimmung | |
| Fruchtigkeit/ Gemüsigkeit | |
| Fleisch/ Meeresfrucht-Note | |
| Tuningvorschlag | |
| Barcode | |
| EAN | "+barcode+" |
\n"+imagestring+"
| Geruch | Gesamt 0/6 | |
| Optik | ||
| Schärfe | ||
| Suppe | ||
| Nudeln |