本文整理汇总了Python中pit.Pit类的典型用法代码示例。如果您正苦于以下问题:Python Pit类的具体用法?Python Pit怎么用?Python Pit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
conf = Pit.get('pw2f', {'require':{'last-time':'yyyy-mm-dd hh:mm:ss+hh:mm'}})
flickr = service.Flickr()
picasaweb = service.Picasaweb()
for album in reversed(picasaweb.get_album_list()):
logging.info('title: %s, published: %s' % (album._title,
album._published))
if not album._title == '2009-12-29_天狗-硫黄' \
and album._published > parse_date(conf['last-time']):
flickr.copy_album_from(picasaweb, album)
else:
logging.debug('skip album %s: published:%s' % (album._title, album._published))
示例2: main
def main():
gmail = Pit.get('gmail', {'require' : {
'user' : 'Gmail account name',
'pass' : 'password for Gmail account',
'fullcount' : '0'
}})
kayac = Pit.get('kayac', {'require' : {
'user' : 'im.kayac.com account name',
'pass' : 'password for im.kayac.com account'
}})
d = feedparser.parse( GMAILATOM % (gmail['user'], gmail['pass']) )
if int(d.feed.fullcount) == int(gmail['fullcount']):
sys.exit(0)
elif int(d.feed.fullcount) > int(gmail['fullcount']):
for e in d.entries:
title = e.title
author = e.author
message = '%s <%s> [%[email protected]]' % (title, author, gmail['user'])
r = notify(message, kayac['user'], kayac['pass'])
if r['result'] != 'posted':
print 'failed', r
sys.exit(2)
Pit.set('gmail', {'data' : {
'user' : gmail['user'],
'pass' : gmail['pass'],
'fullcount' : str(d.feed.fullcount)}})
示例3: test_with_mock_editor
def test_with_mock_editor(self):
import os
ORIGINAL_EDITOR = os.environ.get('EDITOR')
os.environ["EDITOR"] = "./mock_editor.py"
Pit.get('test',
{'require':
{'login': 'your ID',
'passwd': 'GoMa'}})
os.environ["EDITOR"] = ORIGINAL_EDITOR
示例4: test_get_not_exist_key
def test_get_not_exist_key(self):
import os
ORIGINAL_EDITOR = os.environ.get('EDITOR')
os.environ["EDITOR"] = "./mock_editor.py"
Pit.get("NOT_EXIST_KEY",
{'require':
{'login': 'your ID',
'passwd': 'GoMa'}})
os.environ["EDITOR"] = ORIGINAL_EDITOR
示例5: get_credentials
def get_credentials():
"""Get credential information from Pit.
"""
conf = Pit.get("Google")
if "login" not in conf.keys():
# If not exists, exception will be raised
editor = os.environ["EDITOR"]
conf = Pit.get(
'Google', {
'require':{'login':'Google ID','passwd':'Google PassWord'}})
return conf
示例6: test_japan_holiday
def test_japan_holiday():
token = Pit.get('google.api').get('token')
japan_holiday = JapanHoliday(token)
japan_holiday.get_holiday_calender(2015)
# 2015/10/12[Mon] is 体育の日
assert japan_holiday.check(now=datetime.datetime(2015, 10, 12, 0, 0, 0)) is True
assert japan_holiday.check(now=datetime.datetime(2015, 10, 13, 0, 0, 0)) is False
assert japan_holiday.check(now=datetime.datetime(2015, 10, 11, 0, 0, 0), weekend=False) is False
assert japan_holiday.check(now=datetime.datetime(2015, 10, 11, 0, 0, 0), weekend=True) is True
japan_holiday.check(now=datetime.datetime(2016, 10, 2, 0, 0, 0))
assert type(japan_holiday.today()) == bool
japan_holiday.today(weekend=True)
japan_holiday.check()
japan_holiday.check(now=datetime.datetime(2016, 10, 2, 0, 0, 0))
japan_holiday.check(now=datetime.datetime(2016, 10, 2, 0, 0, 0), weekend=True)
# 10000call Within 1 second
ts = time.time()
for x in xrange(10000):
JapanHoliday(token).check(now=datetime.datetime(2016, random.randint(1, 12), 2, 0, 0, 0))
te = time.time()
assert te - ts < 1, te - ts
with pytest.raises(CalenderDoesNotExistError):
japan_holiday.get_holiday_calender(2017)
示例7: connect
def connect(cls):
try:
db_info = Pit.get("db_info")
host = db_info["host"]
user = db_info["username"]
password = db_info["password"]
db = db_info["db"]
# Connect to the database
connection = pymysql.connect(
host=host,
user=user,
password=password,
db=db,
charset="utf8mb4",
cursorclass=pymysql.cursors.DictCursor,
)
connection.autocommit(False)
logger.debug(constants.SEPARATE_LINE)
logger.debug(constants.DB_CONNECTION_ESTABLISHED_MSG)
logger.debug(constants.SEPARATE_LINE)
except IOError:
raise
except Exception:
raise
else:
return connection
示例8: download
def download():
config = Pit.get('flickr.com')
key = config['api_key']
api = flickrapi.FlickrAPI(key)
tags = ['blue', 'red', 'green', 'yellow', 'purple', 'cyan']
index = 0
for tag in tags:
for photo in api.photos_search(tags=tag, sort="relevance", license='2')[0]:
photo_id = photo.attrib['id']
try:
sizes = api.photos_getSizes(photo_id=photo_id)[0]
except:
continue
small = sizes.find('.//size[@label="Small"]')
url = small.attrib['source']
print 'downloading {0} as {1}'.format(url, index)
resp = requests.get(url)
if resp.status_code != 200:
continue
with open('{0}/{1:02d}.jpg'.format(ORIG_DIR, index), 'wb') as f:
for chunk in resp.iter_content():
f.write(chunk)
index += 1
示例9: main
def main(argv=sys.argv[1:]):
parser = argparse.ArgumentParser()
parser.add_argument('img')
args = parser.parse_args(argv)
setting = Pit.get(
'iwdcat',
{'require': {'username': '',
'password': '',
}})
auth_token = setting['username'], setting['password']
url = 'https://gateway.watsonplatform.net/visual-recognition-beta/api/v1/tag/recognize'
res = requests.post(url, auth=auth_token, files={
'imgFile': ('sample.jpg', open(args.img, 'rb')),
})
if res.status_code == requests.codes.ok:
data = json.loads(res.text)
for img in data['images']:
print('{} - {}'.format(img['image_id'], img['image_name']))
for label in img['labels']:
print(' {:30}: {}'.format(label['label_name'], label['label_score']))
else:
print(res.status_code)
print(res.reason)
示例10: create_user
def create_user():
with settings(user='root'):
cuisine.user_ensure('ssmjp')
append('/etc/sudoers', 'ssmjp ALL=(ALL) ALL')
cuisine.ssh_authorize('ssmjp', cuisine.file_local_read('~/.ssh/ssmjp.pub'))
conf = Pit.get('ssmjp-user', { 'require': { 'password': 'Your password' } })
cuisine.user_passwd('ssmjp', conf['password'])
示例11: main
def main():
config = Pit.get('lingr.com', {
'require': {
'user': 'Your lingr user name',
'password': 'Your lingr password'
}
})
lingr = Lingr(config['user'], config['password'])
for event in lingr.stream():
pynotify.init('lingr')
title = None
text = None
img = None
if 'message' in event:
message = event['message']
title = '%[email protected]%s' % (message['nickname'], message['room'])
text = message['text']
img = get_img(message['icon_url'])
elif 'presence' in event:
presence = event['presence']
title = '%[email protected]%s' % (presence['nickname'], presence['room'])
text = presence['status']
img = get_img(presence['icon_url'])
n = pynotify.Notification(title, text, img)
n.show()
示例12: __init__
def __init__(self):
key = Pit.get('twitter.com')
self.consumer_key = key['consumer_key']
self.consumer_secret = key['consumer_secret']
self.access_token = key['access_token']
self.access_token_secret = key['access_token_secret']
示例13: __init__
def __init__(self):
conf = Pit.get('picasaweb', {'require': {'username':'username', 'password':'password'}})
self.gd_client = gdata.photos.service.PhotosService()
self.gd_client.email = conf['username']
self.gd_client.password = conf['password']
self.gd_client.source = 'pw2f picasaweb plugin'
self.gd_client.ProgrammaticLogin()
self.conf = conf
示例14: __call__
def __call__(self):
conf = Pit.get('pplog', {'require': {
'username': '',
'password': '',
}})
return PPlogSecret(
username=conf['username'],
password=conf['password'],
)
示例15: get_Consumersecret
def get_Consumersecret():
"""
pitからcustomer keyを呼ぶ
"""
piConf = Pit.get("twitter-consumer", {'require':
{'ckey': 'ConsumerKey',
'csecret': 'ConsumerSecret'
}})
return(piConf['ckey'], piConf['csecret'])