#!python
#-*- coding:utf-8 -*-

import sys,os.path
import getpass
import time,urllib2,os.path

import requests

def UploadScrShot(f,title):
    #check if file named f exists
    if not os.path.isfile(f):
        raise RuntimeError("file %s does not exist"%f)
    ts=time.localtime()
    url = 'http://webserver.xxx.yyy/ScrShot/upload.php'
    raw_params = dict(year="%4d"%ts.tm_year, 
                      month="%02d"%ts.tm_mon,
                      day="%02d"%ts.tm_mday,
                      )
    fext=os.path.splitext(f)[1][1:]
    UserFile=os.path.split(f)[0]
    files={'UserFile':(
            "imagefile.png",
            open(f,"rb"), 
            "image/%s"%fext
            )
           }
    try:
        s=requests.Session()
        page=s.post(
            url,
            data=raw_params, 
            files=files,
            proxies={ "http":"" } 
            )
        return page
    except:
        raise
