def initialize(self): """Completes the following tasks. 1. Obtain Tumblr OAuth 2. Get basic user info from Tumblr 3. Create directory .dumblr - if directory already exists, we remove it 4. Pickles configuration data into .dumblr/DUMBLR """ d = {} d['config'] = tumblr.Tumblr.oauth() t = tumblr.Tumblr(d['config']['consumer_key'], d['config']['secret_key'], d['config']['oauth_token'], d['config']['oauth_token_secret']) ## IMPORTANT: We only consider blog named after username ## Later update `might` address this issue d['tumblr'] = t.info() if os.path.isdir(self.dumblr_path): shutil.rmtree(self.dumblr_path) os.makedirs(self.dumblr_path) with open(self.CONFIG_FILE, 'w') as f: cPickle.dump(d, f) return self.dumblr_path
def __init__(self): self.fb = fb.Fb() self.tumblr = tumblr.Tumblr() self.twitter = twitter.Twitter() self.insta = insta.Insta() #self.wechat = wechat.Wechat() #self.tel = tele.Telegram() self.myspace = myspace.Myspace() print("cool!")
def __init__(self, name=None, url=None): if name: if not site_class.has_key(name): raise SiteNotSupported() site = site_class[name] self.site = site() else: try: self.url = lib.site.get_orig_url(url) except: self.url = url parsed = urlparse.urlsplit(self.url) netloc = parsed.netloc self.site = None if re.search(r"weibo.com|weibo.cn|sinajs.cn|sinaimg.cn", netloc): self.site = weibo.Weibo() elif re.search(r"meipai.com", netloc): self.site = meipai.Meipai() elif re.search(r"miaopai.com|ent.v.sina.cn", netloc): self.site = miaopai.Miaopai() elif re.search(r"weipai.cn", netloc): self.site = weipai.Weipai() elif re.search(r"vlook.cn", netloc): self.site = vlook.Vlook() elif re.search(r"weipainv.com", netloc): self.site = weipainv.Weipainv() elif re.search(r"xiaoying.tv", netloc): self.site = xiaoying.Xiaoying() elif re.search(r"xiaokaxiu.com", netloc): self.site = xiaokaxiu.Xiaokaxiu() elif re.search(r"gifshow.com|kuaishou.com", netloc): self.site = gifshow.Gifshow() elif re.search(r"v1.cn", netloc): self.site = v1.V1() elif re.search(r"tumblr.com", netloc): self.site = tumblr.Tumblr() elif re.search(r"mitaose8.com", netloc): self.site = mitaose.Mitaose() elif re.search(r"aishipin.net", netloc): self.site = aishipin.Aishipin() else: raise SiteNotSupported()
def do_prod_masses(pif, tform): ddir = tform.tdir.replace('lib', 'pic') print(pif.form.get_str('credit'), ddir, '<br>') if not os.path.exists(ddir): raise useful.SimpleError('Path does not exist.') siz = pif.form.get('tysz') cred = pif.form.get_str('credit') if cred: photog = pif.dbh.fetch_photographer(cred) if not photog: cred = '' for fn, nam in pif.form.get_list(start='nam.'): print('<hr>') print(fn, ddir, siz, nam, '<br>') rf = [False, False, False, False, False] pth = tform.tdir + '/' + fn q = ( 0, 0, ) + imglib.get_size(pth) nname = ddir + '/' + siz + '_' + nam + '.jpg' ts = (400, 0) ofi = imglib.shrinker(pth, nname, q, ts, rf) imglib.simple_save(ofi, nname) images.file_log(nname, tform.tdir) url = pif.secure_prod + nname[1:] link = pif.secure_prod title = nam if cred and not photog.flags & config.FLAG_PHOTOGRAPHER_PRIVATE: title += ' credited to ' + photog.name pif.render.message( 'Post to Tumblr: ', tumblr.Tumblr(pif).create_photo(caption=title, source=url, link=link)) pif.render.message('Credit added: ', pif.dbh.write_photo_credit(cred, ddir, nam))
def _get_tumblr(self): config = self.CONFIG['config'] return tumblr.Tumblr(config['consumer_key'], config['secret_key'], config['oauth_token'], config['oauth_token_secret'])
def action(self, pif, tdir=None, fn=None): log_action = False if not fn: fn = self.fn if not tdir: tdir = self.tdir ret = {'fn': fn, 'dir': tdir, 'act': True} from_path = os.path.join(tdir, fn) to_dir = to_name = '' if self.delete: useful.file_delete(from_path) elif self.trash: useful.file_mover(from_path, os.path.join( '.' + config.TRASH_DIR, from_path[from_path.rfind('/') + 1:]), mv=True, inc=True, trash=False) elif self.archive: useful.file_mover(from_path, os.path.join(tdir, 'archive', fn), mv=True) ret['fn'] = '' elif self.spam: path = '../spam' if os.path.exists(os.path.join( tdir, '..', 'spam')) else 'spam' useful.file_mover(from_path, os.path.join(tdir, path, fn), mv=True) ret['fn'] = '' elif self.fixed: useful.file_mover(from_path, os.path.join(tdir, 'fixed', fn), mv=True) ret['fn'] = '' elif self.rename: if not self.nname: useful.warn('What? (rename, no name)') else: to_dir = tdir to_name = self.nname elif self.lib: if not self.man: useful.warn('What? (lib, no man)') elif not os.path.exists( useful.relpath('.' + config.LIB_MAN_DIR, self.man)): # man2 = pif.dbh.fetch_alias(self.man) # if not man2: useful.warn('bad destination') # else: # useful.file_mover(from_path, os.path.join('.' + config.LIB_MAN_DIR, man2['ref_id'].lower(), fn), # mv=self.mv, ov=self.ov) else: to_dir = useful.relpath('.' + config.LIB_MAN_DIR, self.man) to_name = self.nname elif self.mvbin: if not os.path.exists(os.path.join('lib', self.cat)): useful.warn('bad destination') else: to_dir = os.path.join('lib', self.cat) to_name = self.nname elif self.selcat: if not (self.man or self.nname) or not self.dest: useful.warn('What? (selcat, no name or dest)') else: ddir = self.dest dnam = self.man if self.man else self.nname if self.pref: dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True elif self.select: # inc = self.inc if not self.man: # self.man = tdir[tdir.rfind('/') + 1:] useful.warn('Huh? (select, no man)') else: ddir = '.' + config.IMG_DIR_MAN dnam = self.man if self.var: ddir = '.' + config.IMG_DIR_VAR dnam = dnam + '-' + self.var if self.pref: dnam = self.pref + '_' + dnam elif self.pref: if self.pref != 'n': dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff self.inc = True else: useful.warn("What? (select, no var or pref)") dnam = '' if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True else: ret['act'] = False if to_dir: cred = pif.form.get_str('credit') if cred: photog = pif.dbh.fetch_photographer(cred) if not photog or not photog.flags & config.FLAG_PHOTOGRAPHER_PRIVATE: cred = '' useful.file_mover(from_path, os.path.join(to_dir, to_name), mv=self.mv, ov=self.ov, inc=self.inc) ret['fn'] = to_name ret['dir'] = to_dir if log_action and self.tumblr: title = pif.form.get_str('title', to_name) url = pif.secure_prod + os.path.join(to_dir, to_name) link = pif.secure_prod + self.link title = to_name if cred: title += ' credited to ' + photog.name pif.render.message( 'Post to Tumblr: ', tumblr.Tumblr(pif).create_photo(caption=title, source=url, link=link)) pif.render.message( 'Credit added: ', pif.dbh.write_photo_credit(cred, to_dir, to_name)) return ret