本文整理汇总了Python中util.database.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: daemon
def daemon(code, tc):
while True:
time.sleep(auto_check)
if code.debug:
output.info('Running check for new tweets', 'TWITTER')
# Here we do the work...
for channel in tc:
for tweet_item in tc[channel]:
if tweet_item.startswith('#'): # ID
data = get_tweets(uri_hash % web.quote(tweet_item))
else:
data = get_tweets(uri_user % web.quote(tweet_item), tweet_item)
if not data:
continue
data = data[0]
hash_str = hash(data['text'])
db = database.get(code.default, 'twitter')
if not db: # New data on new database, don't output anywhere..
database.set(code.default, [hash_str], 'twitter')
continue
if hash_str in db:
continue # Same
db.append(hash_str)
database.set(code.default, db, 'twitter')
msg = format(data)
code.msg(channel, msg.decode('ascii', 'ignore'), shorten_urls=False)
db = database.get(code.default, 'twitter')
if db:
if len(db) > 200:
db = db[-200:]
database.set(code.default, db, 'twitter')
示例2: horoscope
def horoscope(inp, db=None, notice=None, nick=None):
"""horoscope <sign> [save] -- Get your horoscope."""
save = False
database.init(db)
if '@' in inp:
nick = inp.split('@')[1].strip()
sign = database.get(db,'users','horoscope','nick',nick)
if not sign: return "No horoscope sign stored for {}.".format(nick)
else:
sign = database.get(db,'users','horoscope','nick',nick)
if not inp:
if not sign:
notice(horoscope.__doc__)
return
else:
if not sign: save = True
if " save" in inp: save = True
sign = inp.split()[0]
url = "http://www.astrology.com/horoscope/daily/%s.html" % sign
try:
request = urllib2.Request(url, None, headers)
page = urllib2.urlopen(request).read()
result = BeautifulSoup(page, 'lxml')
horoscopetxt = http.strip_html(str(result.find('div', attrs={'class':('page-horoscope-text')})))
except: return "Check your spelling, acronyms and short forms are not accepted."
if sign and save: database.set(db,'users','horoscope',sign,'nick',nick)
horoscopetxt = horoscopetxt.rsplit('.', 2)[0]
horoscopetxt += '.'
return u"{}".format(horoscopetxt)
示例3: timefunction2
def timefunction2(inp, nick="", reply=None, db=None, notice=None):
"time [location] [dontsave] | [@ nick] -- Gets time for <location>."
save = True
if '@' in inp:
nick = inp.split('@')[1].strip()
location = database.get(db,'users','location','nick',nick)
if not location: return "No location stored for {}.".format(nick.encode('ascii', 'ignore'))
else:
location = database.get(db,'users','location','nick',nick)
if not inp:
if not location:
notice(time.__doc__)
return
else:
# if not location: save = True
if " dontsave" in inp: save = False
location = inp.split()[0]
# now, to get the actual time
try:
url = "https://time.is/%s" % location.replace(' ','+').replace(' save','')
html = http.get_html(url)
prefix = html.xpath("//div[@id='msgdiv']/h1/a/text()")[0].strip()
curtime = html.xpath("//div[contains(@id,'twd')]/text()")[0].strip()
ampm = html.xpath("//div[contains(@id,'twd')]/span/text()")[0].strip()
date = html.xpath("//h2[contains(@id,'dd')]/text()")[0].strip()
except IndexError:
return "Could not get time for that location."
if location and save: database.set(db,'users','location',location,'nick',nick)
return u'Time in {} is \x02{} {}\x02 [{}]'.format(prefix, curtime, ampm.upper(), date)
示例4: timefunction2
def timefunction2(inp, nick="", reply=None, db=None, notice=None):
"time [location] [dontsave] | [@ nick] -- Gets time for <location>."
save = True
if '@' in inp:
nick = inp.split('@')[1].strip()
location = database.get(db,'users','location','nick',nick)
if not location: return "No location stored for {}.".format(nick.encode('ascii', 'ignore'))
else:
location = database.get(db,'users','location','nick',nick)
if not inp:
if not location:
notice(time.__doc__)
return
else:
# if not location: save = True
if " dontsave" in inp: save = False
location = inp
# now, to get the actual time
url = "https://time.is/%s" % location.replace(' ','_').replace(' save','')
try:
request = urllib2.Request(url, None, headers)
page = urllib2.urlopen(request).read()
soup = BeautifulSoup(page, 'lxml')
soup = soup.find('div', attrs={'id': re.compile('time_section')})
time = filter(None, http.strip_html(soup.find('div', attrs={'id': re.compile('twd')}).renderContents().strip()))
details = filter(None, http.strip_html(soup.find('div', attrs={'id': re.compile('dd')}).renderContents().strip()))
prefix = filter(None, http.strip_html(soup.find('div', attrs={'id': re.compile('msgdiv')}).renderContents().strip()))
except IndexError:
return "Could not get time for that location."
return formatting.output('Time', [u'{} {}, {}'.format(prefix.decode('ascii', 'ignore'), time, details)])
示例5: time
def time(inp, nick="", reply=None, db=None, notice=None):
"time [location] [dontsave] | [@ nick] -- Gets time for <location>."
save = True
if '@' in inp:
nick = inp.split('@')[1].strip()
location = database.get(db,'users','location','nick',nick)
if not location: return "No location stored for {}.".format(nick.encode('ascii', 'ignore'))
else:
location = database.get(db,'users','location','nick',nick)
if not inp:
if not location:
notice(time.__doc__)
return
else:
if not location: save = True
if " save" in inp: save = True
location = inp.split()[0]
# now, to get the actual time
try:
url = "https://www.google.com/search?q=time+in+%s" % location.replace(' ','+').replace(' save','')
html = http.get_html(url)
prefix = html.xpath("//div[contains(@class,'vk_c vk_gy')]//span[@class='vk_gy vk_sh']/text()")[0].strip()
curtime = html.xpath("//div[contains(@class,'vk_c vk_gy')]//div[@class='vk_bk vk_ans']/text()")[0].strip()
day = html.xpath("//div[contains(@class,'vk_c vk_gy')]//div[@class='vk_gy vk_sh']/text()")[0].strip()
date = html.xpath("//div[contains(@class,'vk_c vk_gy')]//div[@class='vk_gy vk_sh']/span/text()")[0].strip()
except IndexError:
return "Could not get time for that location."
if location and save: database.set(db,'users','location',location,'nick',nick)
return u'{} is \x02{}\x02 [{} {}]'.format(prefix, curtime, day, date)
示例6: mug
def mug(inp, db=None, nick=None, chan=None, conn=None, notice=None):
"""mug <user> -- Takes money from <user>.."""
inp = inp.split()
user = inp[0]
money = float(random.randint(20, 1500))
try:
money = inp[-1].split('.')[0] + '.' + inp[-1].split('.')[1][0:2]
money = float(money)
except:
pass
try:
robber = float(database.get(db,'users','fines','nick',nick))
except:
robber = 0.0
try:
victim = float(database.get(db,'users','fines','nick',user))
except:
victim = 0.0
robbingfails = random.randint(1, 3)
if robbingfails == 2:
if victim != robber:
database.set(db,'users','fines',robber + money,'nick', nick)
database.set(db,'users','fines',victim - money,'nick',user)
conn.send(u"PRIVMSG {} :\x01ACTION {} shoots you in the foot and takes \x02${}\x02.\x01".format(chan, user, money))
else:
if robber != victim:
database.set(db,'users','fines',victim + money,'nick', user)
database.set(db,'users','fines',robber - money,'nick', nick)
conn.send(u"PRIVMSG {} :\x01ACTION {} shanks {} in a dark alley and takes \x02${}\x02\x01".format(chan, nick, user, money))
示例7: horoscope
def horoscope(inp, db=None, notice=None, nick=None):
"""horoscope <sign> [save] -- Get your horoscope."""
save = False
database.init(db)
if '@' in inp:
nick = inp.split('@')[1].strip()
sign = database.get(db,'users','horoscope','nick',nick)
if not sign: return "No horoscope sign stored for {}.".format(nick)
else:
sign = database.get(db,'users','horoscope','nick',nick)
if not inp:
if not sign:
notice(horoscope.__doc__)
return
else:
if not sign: save = True
if " save" in inp: save = True
sign = inp.split()[0]
import urllib
url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
try:
response = urllib.urlopen(url)
result = response.read()
horoscopetxt = result.find('div', {'class': 'block-horoscope-text f16 l20'}).text
except: return "Could not get the horoscope for {}.".format(sign.encode('utf8'))
if sign and save: database.set(db,'users','horoscope',sign,'nick',nick)
return u"\x02{}\x02 {}".format(sign, horoscopetxt)
示例8: onjoined
def onjoined(inp,input=None, conn=None, chan=None,raw=None, db=None):
database.set(db,'users','mask',input.mask.lower().replace('~',''),'nick',input.nick.lower())
mask = user.format_hostmask(input.mask)
disabled_commands = database.get(db,'channels','disabled','chan',chan)
if not disabled_commands: disabled_commands = ""
#if not 'banlist' in disabled_commands:
# #check if bans
# banlist = database.get(db,'channels','bans','chan',chan)
# if banlist and mask in banlist:
# conn.send(u"MODE {} {} *{}".format(input.chan, '+b', mask))
# conn.send(u"KICK {} {} :{}".format(input.chan, input.nick, 'I dont think so Tim.'))
if not 'autoop' in disabled_commands:
#check if ops
autoop = database.get(db,'channels','autoop','chan',chan)
if autoop: autoops = database.get(db,'channels','admins','chan',chan)
else: autoops = database.get(db,'channels','autoops','chan',chan)
if autoops and mask in autoops:
conn.send(u"MODE {} {} {}".format(input.chan, '+o', input.nick))
if not 'greeting' in disabled_commands:
# send greeting
greeting = database.get(db,'users','greeting','nick',input.nick)
if greeting: return greeting
示例9: horoscope
def horoscope(inp, db=None, notice=None, nick=None):
"""horoscope <sign> [save] -- Get your horoscope."""
save = False
database.init(db)
if '@' in inp:
nick = inp.split('@')[1].strip()
sign = database.get(db,'users','horoscope','nick',nick)
if not sign: return "No horoscope sign stored for {}.".format(nick)
else:
sign = database.get(db,'users','horoscope','nick',nick)
if not inp:
if not sign:
notice(horoscope.__doc__)
return
else:
if not sign: save = True
if " save" in inp: save = True
sign = inp.split()[0]
url = "http://my.horoscope.com/astrology/free-daily-horoscope-%s.html" % sign
try:
result = http.get_soup(url)
title = result.find_all('h1', {'class': 'h1b'})[1].text
horoscopetxt = result.find('div', {'id': 'textline'}).text
except: return "Could not get the horoscope for {}.".format(sign.encode('utf8'))
if sign and save: database.set(db,'users','horoscope',sign,'nick',nick)
return u"\x02{}\x02 {}".format(title, horoscopetxt)
示例10: weather
def weather(inp, nick=None, reply=None, db=None, notice=None):
"weather | <location> [save] | <@ user> -- Gets weather data for <location>."
save = True
if '@' in inp:
save = False
nick = inp.split('@')[1].strip()
loc = database.get(db,'users','location','nick',nick)
if not loc: return "No location stored for {}.".format(nick.encode('ascii', 'ignore'))
else:
loc = database.get(db,'users','location','nick',nick)
if not inp:
if not loc:
notice(weather.__doc__)
return
else:
# if not loc: save = True
if " dontsave" in inp:
inp = inp.replace(' dontsave','')
save = False
loc = inp.replace(' ','_') #.split()[0]
location = http.quote_plus(loc)
# location = location.replace(',','').replace(' ','-')
# now, to get the actual weather
try:
data = get_weather('%s' % location)
except KeyError:
return "Could not get weather for that location."
if location and save: database.set(db,'users','location',location,'nick',nick)
# put all the stuff we want to use in a dictionary for easy formatting of the output
weather_data = {
"place": data['location']['city'],
"conditions": data['item']['condition']['text'],
"temp_f": data['item']['condition']['temp'],
"temp_c": data['item']['condition']['temp_c'],
"humidity": data['atmosphere']['humidity'],
"wind_kph": data['wind']['speed_kph'],
"wind_mph": data['wind']['speed'],
"wind_text": data['wind']['text'],
"forecast": data['item']['forecast'][0]['text'],
"high_f": data['item']['forecast'][0]['high'],
"high_c": data['item']['forecast'][0]['high_c'],
"low_f": data['item']['forecast'][0]['low'],
"low_c": data['item']['forecast'][0]['low_c'],
"_forecast": data['item']['forecast'][1]['text'],
"_high_f": data['item']['forecast'][1]['high'],
"_high_c": data['item']['forecast'][1]['high_c'],
"_low_f": data['item']['forecast'][1]['low'],
"_low_c": data['item']['forecast'][1]['low_c']
}
reply("\x02{place}\x02 - \x02Current:\x02 {conditions}, {temp_f}F/{temp_c}C, Humidity: {humidity}%, " \
"Wind: {wind_kph}KPH/{wind_mph}MPH {wind_text}, \x02Today:\x02 {forecast}, " \
"High: {high_f}F/{high_c}C, Low: {low_f}F/{low_c}C. " \
"\x02Tomorrow:\x02 {_forecast}, High: {_high_f}F" \
"/{_high_c}C, Low: {_low_f}F/{_low_c}C.".format(**weather_data))
示例11: host
def host(inp, nick=None, conn=None, db=None):
# return user.get_hostmask(inp,db)
if not inp:
inp = nick
db_host = database.get(db, 'users', 'mask', 'nick', inp)
if inp is db_host:
db_host = database.get(db, 'seen', 'host', 'name', inp)
return "{}: {}".format(inp, db_host)
示例12: badwords
def badwords(inp, notice=None, bot=None, chan=None, db=None):
"""disabled [#channel] -- Lists disabled commands/."""
if len(inp) == 0 or 'list' in inp:
badwordlist = database.get(db, 'channels', 'badwords', 'chan', chan)
if badwordlist:
notice(u"[{}]: Bad words: {}".format(chan, badwordlist))
else:
notice(u"[{}]: No bad words in list.".format(chan))
notice(badwords.__doc__)
elif 'add' or 'del' in inp:
command = inp.split(' ')[0].strip()
inp = inp.replace(command, '').strip()
badwordlist = database.get(db, 'channels', 'badwords', 'chan', chan)
targets = inp.split()
if 'add' in command:
for target in targets:
if badwordlist and target in badwordlist:
notice(
u"[{}]: {} is already a bad word.".format(
chan, target))
else:
if len(target) < 3:
s = u"[{}]: badwords must be longer than 3 " \
"characters. ({})"
notice(s.format(chan, target))
else:
badwordlist = '{} {}'.format(target, badwordlist)
database.set(
db, 'channels', 'badwords',
badwordlist, 'chan', chan)
s = u"[{}]: {} has been added to the bad word list."
notice(s.format(chan, target))
elif 'del' in command:
if 'all' in targets or '*' in targets:
database.set(db, 'channels', 'badwords', '', 'chan', chan)
notice(u"[{}]: All bad words have been removed.".format(chan))
else:
for target in targets:
if badwordlist and target in badwordlist:
badwordlist = " ".join(
badwordlist.replace(
target, '').strip().split())
database.set(
db, 'channels', 'badwords', badwordlist, 'chan',
chan)
notice(
u"[{}]: {} is no longer a bad word.".format(
chan, target))
else:
notice(
u"[{}]: {} is not a bad word.".format(
chan, target))
else:
notice(badwords.__doc__)
return
示例13: process_vote
def process_vote(target,action,chan,mask,db,notice,conn):
if ' ' in target:
notice('Invalid nick')
return
try: votes2kick = database.get(db,'channels','votekick','chan',chan)
except: votes2kick = 10
try: votes2ban = database.get(db,'channels','voteban','chan',chan)
except: votes2ban = 10
if len(target) is 0:
if action is 'kick': notice('Votes required to kick: {}'.format(votes2kick))
elif action is 'ban': notice('Votes required to ban: {}'.format(votes2ban))
return
votefinished = False
global db_ready
if not db_ready: db_init(db)
chan = chan.lower()
target = target.lower()
voter = user.format_hostmask(mask)
oters = db.execute("SELECT voters FROM votes where chan='{}' and action='{}' and target like '{}'".format(chan,action,target)).fetchone()
if conn.nick.lower() in target: return "I dont think so Tim."
if voters:
voters = voters[0]
if voter in voters:
notice("You have already voted.")
return
else:
voters = '{} {}'.format(voters,voter).strip()
notice("Thank you for your vote!")
else:
voters = voter
votecount = len(voters.split(' '))
if 'kick' in action:
votemax = int(votes2kick)
if votecount >= votemax:
votefinished = True
conn.send("KICK {} {} :{}".format(chan, target, "You have been voted off the island."))
if 'ban' in action:
votemax = int(votes2ban)
if votecount >= votemax:
votefinished = True
conn.send("MODE {} +b {}".format(chan, user.get_hostmask(target,db)))
conn.send("KICK {} {} :".format(chan, target, "You have been voted off the island."))
if votefinished: db.execute("DELETE FROM votes where chan='{}' and action='{}' and target like '{}'".format(chan,action,target))
else: db.execute("insert or replace into votes(chan, action, target, voters, time) values(?,?,?,?,?)", (chan, action, target, voters, time.time()))
db.commit()
return ("Votes to {} {}: {}/{}".format(action, target, votecount,votemax))
示例14: showfloods
def showfloods(inp, chan=None, notice=None, db=None):
"""showfloods [channel]-- Shows flood settings."""
flood = database.get(db,'channels','flood','chan',chan)
if flood: notice(u"[{}]: Flood: {} messages in {} seconds".format(chan,flood.split()[0],flood.split()[1]))
else: notice(u"[{}]: Flood protection is disabled.".format(chan))
cmdflood = database.get(db,'channels','cmdflood','chan',chan)
if cmdflood: notice(u"[{}]: Command Flood: {} commands in {} seconds".format(chan,cmdflood.split()[0],cmdflood.split()[1]))
else: notice(u"[{}]: Command Flood protection is disabled.".format(chan))
return
示例15: get_hostmask
def get_hostmask(inp, db):
"userhost -- Returns a nicks userhost"
if "@" in inp or "." in inp:
return inp
nick = inp.strip().replace("~", "").lower()
db_host = database.get(db, "users", "mask", "nick", nick)
if db_host is False:
db_host = database.get(db, "seen", "host", "name", nick)
if db_host is False:
db_host = nick
return format_hostmask(db_host)