• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python web.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sopel.web.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: woeid_search

def woeid_search(query):
    """
    Find the first Where On Earth ID for the given query. Result is the etree
    node for the result, so that location data can still be retrieved. Returns
    None if there is no result, or the woeid field is empty.
    """
    query = 'q=select woeid from geo.places where text="%s"' % query
    body = web.get('http://query.yahooapis.com/v1/public/yql?' + query,
                   dont_decode=True)
    parsed = xmltodict.parse(body).get('query')
    results = parsed.get('results')
    if not results:
        return None
    elif type(results) is collections.OrderedDict:
        place = results.get('place')
    elif type(results) is list:
        place = results[0].get('place')
    else:
        return None
    if not place:
        return None
    elif type(place) is collections.OrderedDict:
        return place
    elif type(place) is list:
        return place[0]
    else:
        return None
开发者ID:shamazar,项目名称:willie-modules,代码行数:27,代码来源:new_weather.py


示例2: find_title

def find_title(url):
    """Return the title for the given URL."""
    try:
        content, headers = web.get(url, return_headers=True, limit_bytes=max_bytes)
    except UnicodeDecodeError:
        return  # Fail silently when data can't be decoded

    # Some cleanup that I don't really grok, but was in the original, so
    # we'll keep it (with the compiled regexes made global) for now.
    content = title_tag_data.sub(r'<\1title>', content)
    content = quoted_title.sub('', content)

    start = content.find('<title>')
    end = content.find('</title>')
    if start == -1 or end == -1:
        return
    title = web.decode(content[start + 7:end])
    title = title.strip()[:200]

    title = ' '.join(title.split())  # cleanly remove multiple spaces

    # More cryptic regex substitutions. This one looks to be myano's invention.
    title = re_dcc.sub('', title)

    return title or None
开发者ID:Cnwauche,项目名称:sopel,代码行数:25,代码来源:url.py


示例3: ytsearch

def ytsearch(bot, trigger):
    """
    .youtube <query> - Search YouTube
    """
    if not trigger.group(2):
        return
    uri = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q=' + trigger.group(2)
    raw = web.get('{0}&key={1}'.format(uri, bot.config.google.public_key))
    vid = json.loads(raw)['items'][0]['id']['videoId']
    uri = 'https://www.googleapis.com/youtube/v3/videos?id=' + vid + '&part=contentDetails,snippet,statistics'
    video_info = ytget(bot, trigger, uri)
    if video_info is None:
        return

    title = video_info['snippet']['title']
    uploader = video_info['snippet']['channelTitle']
    duration = video_info['contentDetails']['duration']
    views = video_info['statistics']['viewCount']
    likes = video_info['statistics']['likeCount']
    dislikes = video_info['statistics']['dislikeCount']

    message = '[YT Search] {0} | https://youtu.be/{1} | Duration: {2} | Views: {3} | Uploader: {4} | {5} | {6}'.format(
      bold(title), video_info['id'], duration, views, uploader, color(likes, colors.GREEN), color(dislikes, colors.RED))

    bot.say(message)
开发者ID:vemacs,项目名称:foxbot-modules,代码行数:25,代码来源:youtube.py


示例4: uptime

def uptime(bot, trigger):
    """
    Report the stream uptime.
    """
    try:
        query_url = 'https://api.twitch.tv/kraken/streams/{0}?api_version=3&client_id={1}'
        answer = web.get(query_url.format(trigger.sender[1:],
                                          bot.config.LRB.api_key))
    except:
        return bot.reply("Couldn't contact the Twitch API servers. :( #BlameTwitch")

    try:
        data = json.loads(answer)
    except:
        return bot.reply("The Twitch API returned an invalid object. :( #BlameTwitch")

    if data['stream'] != None:
        startTime = data['stream']['created_at']
    else:
        return bot.reply("Stream offline. :(")

    f = '%Y-%m-%dT%H:%M:%SZ'

    tStart = datetime.datetime.strptime(startTime, f)
    now = datetime.datetime.utcnow()
    uptime = (now - tStart).seconds

    h, r = divmod(uptime, 3600)
    m, s = divmod(r, 60)

    if h > 0:
        return bot.reply('Stream has been online for %s:%s:%s' % (h,m,s))
    else:
        return bot.reply('Stream has been online for %s:%s' % (m,s))
开发者ID:tyrope,项目名称:lionroarbot,代码行数:34,代码来源:LRB_Uptime.py


示例5: weather

def weather(bot, trigger):
    """.weather location - Show the weather at the given location."""

    location = trigger.group(2)
    woeid = ""
    if not location:
        woeid = bot.db.get_nick_value(trigger.nick, "woeid")
        if not woeid:
            return bot.msg(
                trigger.sender,
                "I don't know where you live. "
                + "Give me a location, like .weather London, or tell me where you live by saying .setlocation London, for example.",
            )
    else:
        location = location.strip()
        woeid = bot.db.get_nick_value(location, "woeid")
        if woeid is None:
            first_result = woeid_search(location)
            if first_result is not None:
                woeid = first_result.get("woeid")

    if not woeid:
        return bot.reply("I don't know where that is.")

    query = "q=select * from weather.forecast where woeid=\"%s\" and u='c'" % woeid
    body = web.get("http://query.yahooapis.com/v1/public/yql?" + query, dont_decode=True)
    parsed = xmltodict.parse(body).get("query")
    results = parsed.get("results")
    location = results.get("channel").get("title")
    cover = get_cover(results)
    temp = get_temp(results)
    humidity = get_humidity(results)
    wind = get_wind(results)
    bot.say("%s: %s, %s, %s, %s" % (location, cover, temp, humidity, wind))
开发者ID:chevanlol360,项目名称:sopel,代码行数:34,代码来源:weather.py


示例6: wikt

def wikt(word):
    bytes = web.get(uri % web.quote(word))
    bytes = r_ul.sub('', bytes)

    mode = None
    etymology = None
    definitions = {}
    for line in bytes.splitlines():
        if 'id="Etymology"' in line:
            mode = 'etymology'
        elif 'id="Noun"' in line:
            mode = 'noun'
        elif 'id="Verb"' in line:
            mode = 'verb'
        elif 'id="Adjective"' in line:
            mode = 'adjective'
        elif 'id="Adverb"' in line:
            mode = 'adverb'
        elif 'id="Interjection"' in line:
            mode = 'interjection'
        elif 'id="Particle"' in line:
            mode = 'particle'
        elif 'id="Preposition"' in line:
            mode = 'preposition'
        elif 'id="' in line:
            mode = None

        elif (mode == 'etmyology') and ('<p>' in line):
            etymology = text(line)
        elif (mode is not None) and ('<li>' in line):
            definitions.setdefault(mode, []).append(text(line))

        if '<hr' in line:
            break
    return etymology, definitions
开发者ID:dasu,项目名称:sopel,代码行数:35,代码来源:wiktionary.py


示例7: movie

def movie(bot, trigger):
    """
    Returns some information about a movie, like Title, Year, Rating, Genre and IMDB Link.
    """
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    uri = "http://www.omdbapi.com/?t=" + word
    u = web.get(uri, 30)
    data = json.loads(u)  # data is a Dict containing all the information we need
    if data["Response"] == "False":
        if "Error" in data:
            message = "[MOVIE] %s" % data["Error"]
        else:
            LOGGER.warning("Got an error from the OMDb api, search phrase was %s; data was %s", word, str(data))
            message = "[MOVIE] Got an error from OMDbapi"
    else:
        message = (
            "[MOVIE] Title: "
            + data["Title"]
            + " | Year: "
            + data["Year"]
            + " | Rating: "
            + data["imdbRating"]
            + " | Genre: "
            + data["Genre"]
            + " | IMDB Link: http://imdb.com/title/"
            + data["imdbID"]
        )
    bot.say(message)
开发者ID:daniellawrence,项目名称:sopel,代码行数:30,代码来源:movie.py


示例8: vimeo_by_url

def vimeo_by_url(bot, trigger, found_match=None):
    match = found_match or trigger
    videoID = match.group(2)
    apiURL = "https://vimeo.com/api/v2/video/" + videoID + ".json"
    try:
        resp = json.loads(web.get(apiURL))
    except:
        return

    output = u"[Vimeo] "
    output += u"Title: %s" % (str(resp[0]['title']))
    if 'user_name' in resp[0]:
        output += u" | Uploader: %s" % (str(resp[0]['user_name']))
    if 'upload_date' in resp[0]:
        output += u" | Uploaded: %s" % (str(resp[0]['upload_date']))
    if 'duration' in resp[0]:
        output += u" | Duration: %s" % (str(resp[0]['duration']))
    if 'stats_number_of_plays' in resp[0]:
        output += u" | Views : %s" % (str(resp[0]['stats_number_of_plays']))
    if 'stats_number_of_comments' in resp[0]:
        output += u" | Comments: %s" % (str(resp[0]['stats_number_of_comments']))
    if 'stats_number_of_likes' in resp[0]:
        output += u" | Likes: %s" % (str(resp[0]['stats_number_of_likes']))

    bot.say(output)
开发者ID:arza-zara,项目名称:Sopel-modules,代码行数:25,代码来源:vimeo.py


示例9: short_cancelled

def short_cancelled(bot, trigger):
    """Display short list of cancelled courses at MUN"""
    page, headers = web.get(uri, return_headers=True)
    if headers['_http_status'] != 200:
        bot.say('Couldn\'t find cancellation information.')
        return
    parsed = html.fromstring(page)
    middle = parsed.get_element_by_id('middle')
    contents = list(middle)
    reply = ''
    for element in contents:
        if element.tag=='p' and element.text_content() == '________________________________________':
            break
        elif element.tag=='h2':
            printed = True
            text = element.text_content()
            day = parser.parse(text)
            if day.date() == datetime.today().date():
                reply += '| MUN\'s Cancellations for ' + bold(text) + ' (TODAY): '
            else:
                reply += '| MUN\'s Cancellations for ' + bold(text) + ': '
        elif element.tag=='p':
            text = element.text_content()
            course = list(element)[0].text_content()
            reply += course + ', '
    bot.say(reply[2:-2])
    bot.say('Use \'.canceldetail\' for more detailed information')
开发者ID:echoenzo,项目名称:Nibbles,代码行数:27,代码来源:muncancellations.py


示例10: bing_search

def bing_search(query, lang="en-GB"):
    base = "http://www.bing.com/search?mkt=%s&q=" % lang
    bytes = web.get(base + query)
    m = r_bing.search(bytes)
    #    print m
    if m:
        return m.group(1)
开发者ID:dren95,项目名称:rotobot,代码行数:7,代码来源:rotobot.py


示例11: movie

def movie(bot, trigger):
    """
    Returns some information about a movie, like Title, Year, Rating, Genre and IMDB Link.
    """
    if not trigger.group(2):
        return
    word = trigger.group(2).rstrip()
    uri = "http://www.imdbapi.com/?t=" + word
    u = web.get(uri, 30)
    data = json.loads(u)  # data is a Dict containing all the information we need
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[MOVIE] %s' % data['Error']
        else:
            LOGGER.warning(
                'Got an error from the imdb api, search phrase was %s; data was %s',
                word, str(data))
            message = '[MOVIE] Got an error from imdbapi'
    else:
        message = '[MOVIE] Title: ' + data['Title'] + \
                  ' | Year: ' + data['Year'] + \
                  ' | Rating: ' + data['imdbRating'] + \
                  ' | Genre: ' + data['Genre'] + \
                  ' | IMDB Link: http://imdb.com/title/' + data['imdbID']
    bot.say(message)
开发者ID:firerogue,项目名称:sopel,代码行数:25,代码来源:movie.py


示例12: cancelled

def cancelled(bot, trigger):
    """Show current cancelled classes at MUN"""
    page, headers = web.get(uri, return_headers=True)
    if headers['_http_status'] != 200:
        bot.say('Couldn\'t find cancellation information.')
        return
    parsed = html.fromstring(page)
    middle = parsed.get_element_by_id('middle')
    contents = list(middle)
    reply = []
    if trigger.nick != trigger.sender:
        bot.reply('I\'m messaging you with a detailed cancellation list!')
    for element in contents:
        if element.tag=='p' and element.text_content() == '________________________________________':
            break
        elif element.tag=='h2':
            printed = True
            text = element.text_content()
            day = parser.parse(text)
            if day.date() == datetime.today().date():
                reply.append('MUN\'s Cancellations for ' + bold(text) + ' (TODAY):')
            else:
                reply.append('MUN\'s Cancellations for ' + bold(text) + ': ')
        elif element.tag=='p':
            text = element.text_content()
            course = list(element)[0].text_content()
            reply.append(bold(course) + text[len(course):])
    for a in reply:
        bot.msg(trigger.nick, a)
开发者ID:echoenzo,项目名称:Nibbles,代码行数:29,代码来源:muncancellations.py


示例13: weather

def weather(bot, trigger):
    """.weather location - Show the weather at the given location."""

    location = trigger.group(2)
    woeid = ''
    if not location:
        woeid = bot.db.get_nick_value(trigger.nick, 'woeid')
        if not woeid:
            return bot.msg(trigger.sender, "I don't know where you live. " +
                           'Give me a location, like .weather London, or tell me where you live by saying .setlocation London, for example.')
    else:
        location = location.strip()
        woeid = bot.db.get_nick_value(location, 'woeid')
        if woeid is None:
            first_result = woeid_search(location)
            if first_result is not None:
                woeid = first_result.get('woeid')

    if not woeid:
        return bot.reply("I don't know where that is.")

    query = web.urlencode({'w': woeid, 'u': 'c'})
    raw = web.get('http://weather.yahooapis.com/forecastrss?' + query,
                  dont_decode=True)
    parsed = xmltodict.parse(raw).get('rss')
    location = parsed.get('channel').get('title')

    cover = get_cover(parsed)
    temp = get_temp(parsed)
    humidity = get_humidity(parsed)
    wind = get_wind(parsed)
    bot.say(u'%s: %s, %s, %s, %s' % (location, cover, temp, humidity, wind))
开发者ID:Cnwauche,项目名称:sopel,代码行数:32,代码来源:weather.py


示例14: find_title

def find_title(url=None, content=None):
    """Return the title for the given URL.

    Copy of find_title that allows for avoiding duplicate requests."""
    if (not content and not url) or (content and url):
        raise ValueError("url *or* content needs to be provided to find_title")
    if url:
        try:
            content, headers = web.get(url, return_headers=True, limit_bytes=max_bytes)
        except UnicodeDecodeError:
            return  # Fail silently when data can't be decoded
    assert content

    # Some cleanup that I don't really grok, but was in the original, so
    # we'll keep it (with the compiled regexes made global) for now.
    content = title_tag_data.sub(r"<\1title>", content)
    content = quoted_title.sub("", content)

    start = content.find("<title>")
    end = content.find("</title>")
    if start == -1 or end == -1:
        return
    title = web.decode(content[start + 7 : end])
    title = title.strip()[:200]

    title = " ".join(title.split())  # cleanly remove multiple spaces

    # More cryptic regex substitutions. This one looks to be myano's invention.
    title = re_dcc.sub("", title)

    return title or None
开发者ID:CrushAndRun,项目名称:sopel-Bodhi-extras,代码行数:31,代码来源:bookie.py


示例15: etymology

def etymology(word):
    # @@ <nsh> sbp, would it be possible to have a flag for .ety to get 2nd/etc
    # entries? - http://swhack.com/logs/2006-07-19#T15-05-29

    if len(word) > 25:
        raise ValueError("Word too long: %s[...]" % word[:10])
    word = {'axe': 'ax/axe'}.get(word, word)

    bytes = web.get(etyuri % word)
    definitions = r_definition.findall(bytes)

    if not definitions:
        return None

    defn = text(definitions[0])
    m = r_sentence.match(defn)
    if not m:
        return None
    sentence = m.group(0)

    maxlength = 275
    if len(sentence) > maxlength:
        sentence = sentence[:maxlength]
        words = sentence[:-5].split(' ')
        words.pop()
        sentence = ' '.join(words) + ' [...]'

    sentence = '"' + sentence.replace('"', "'") + '"'
    return sentence + ' - ' + (etyuri % word)
开发者ID:firerogue,项目名称:sopel,代码行数:29,代码来源:etymology.py


示例16: isup

def isup(bot, trigger):
    """isup.me website status checker"""
    site = trigger.group(2)
    if not site:
        return bot.reply("What site do you want to check?")

    if site[:6] != 'http://' and site[:7] != 'https://':
        if '://' in site:
            protocol = site.split('://')[0] + '://'
            return bot.reply("Try it again without the %s" % protocol)
        else:
            site = 'http://' + site

    if not '.' in site:
        site += ".com"

    try:
        response = web.get(site)
    except Exception:
        bot.say(site + ' looks down from here.')
        return

    if response:
        bot.say(site + ' looks fine to me.')
    else:
        bot.say(site + ' is down from here.')
开发者ID:mvk,项目名称:sopel,代码行数:26,代码来源:isup.py


示例17: weather

def weather(bot, trigger):
    """.weather location - Show the weather at the given location."""

    location = trigger.group(2)
    woeid = ''
    if not location:
        woeid = bot.db.get_nick_value(trigger.nick, 'woeid')
        if not woeid:
            return bot.msg(trigger.sender, "I don't know where you live. " +
                           'Give me a location, like .weather London, or tell me where you live by saying .setlocation London, for example.')
    else:
        location = location.strip()
        woeid = bot.db.get_nick_value(location, 'woeid')
        if woeid is None:
            first_result = woeid_search(location)
            if first_result is not None:
                woeid = first_result.get('woeid')

    if not woeid:
        return bot.reply("I don't know where that is.")

    query = 'q=select * from weather.forecast where woeid="%s" and u=\'c\'' % woeid
    body = web.get('http://query.yahooapis.com/v1/public/yql?' + query,
                  dont_decode=True)
    parsed = xmltodict.parse(body).get('query')
    results = parsed.get('results')
    if results is None:
        return bot.reply("No forecast available. Try a more specific location.")
    location = results.get('channel').get('title')
    cover = get_cover(results)
    temp = get_temp(results)
    humidity = get_humidity(results)
    wind = get_wind(results)
    bot.say(u'%s: %s, %s, %s, %s' % (location, cover, temp, humidity, wind))
开发者ID:JonasHogman,项目名称:musicbot,代码行数:34,代码来源:weather.py


示例18: show_bug

def show_bug(bot, trigger, match=None):
    """Show information about a Bugzilla bug."""
    match = match or trigger
    domain = match.group(1)
    if domain not in bot.config.bugzilla.domains:
        return
    url = 'https://%s%sctype=xml&%s' % match.groups()
    data = web.get(url, dont_decode=True)
    bug = xmltodict.parse(data).get('bugzilla').get('bug')

    message = ('[BUGZILLA] %s | Product: %s | Component: %s | Version: %s | ' +
               'Importance: %s |  Status: %s | Assigned to: %s | ' +
               'Reported: %s | Modified: %s')

    resolution = bug.get('resolution')
    if resolution is not None:
        status = bug.get('bug_status') + ' ' + resolution
    else:
        status = bug.get('bug_status')

    message = message % (
        bug.get('short_desc'), bug.get('product'),
        bug.get('component'), bug.get('version'),
        (bug.get('priority') + ' ' + bug.get('bug_severity')),
        status, bug.get('assigned_to').get('@name'), bug.get('creation_ts'),
        bug.get('delta_ts'))
    bot.say(message)
开发者ID:firerogue,项目名称:sopel,代码行数:27,代码来源:bugzilla.py


示例19: get_np_info

def get_np_info(username):
    username = web.quote(username)
    api_key = "782c02b1c96ae181d83850f050509103"
    recent_tracks = web.get("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&format=json&user=%s&api_key=%s" % (username, api_key))

    #now playing track, or most recently scrobbled track
    now_playing = json.loads(recent_tracks)

    # if the user does not exist
    if 'recenttracks' not in now_playing:
        return None

    now_playing = now_playing['recenttracks']['track'][0]

    track = now_playing['name']
    album = now_playing['album']['#text']
    artist = now_playing['artist']['#text']

    # why the fuck doesnt this work with web.get() ???
    track_page = urllib.request.urlopen("http://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json&artist=%s&track=%s&username=%s&api_key=%s" % (web.quote(artist), web.quote(track), username, api_key))
    track_info = json.loads(track_page.read().decode())['track']
    user_playcount = "0"
    if 'userplaycount' in track_info:
        user_playcount = track_info['userplaycount']
    user_loved = False
    if int(track_info['userloved']) > 0:
        user_loved = True

    return {"track": track, "album": album, "artist": artist, "user_playcount": user_playcount, "user_loved": user_loved}
开发者ID:arza-zara,项目名称:Sopel-modules,代码行数:29,代码来源:lastfm.py


示例20: query_lastfm

def query_lastfm(bot, **kwargs):
    args = []
    for k in kwargs:
        args.append("{}={}".format(k, kwargs[k]))
    args.append("api_key={}".format(get_api_key(bot)))
    args.append("format=json")
    url = "http://ws.audioscrobbler.com/2.0/?" + "&".join(args)
    return web.get(url)
开发者ID:la11111,项目名称:willie-modules,代码行数:8,代码来源:lastfm.py



注:本文中的sopel.web.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python web.quote函数代码示例发布时间:2022-05-27
下一篇:
Python time.get_timezone函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap