当前位置: 首页>>代码示例>>Python>>正文


Python Weather.get_weather方法代码示例

本文整理汇总了Python中weather.Weather.get_weather方法的典型用法代码示例。如果您正苦于以下问题:Python Weather.get_weather方法的具体用法?Python Weather.get_weather怎么用?Python Weather.get_weather使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weather.Weather的用法示例。


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

示例1: edition

# 需要导入模块: from weather import Weather [as 别名]
# 或者: from weather.Weather import get_weather [as 别名]
def edition(request):

    if not request.GET.get('athlete_id', False):
        return HttpResponse("No athlete ID was provided", status=400)
    
    # Get user and event
    athlete_id = request.GET['athlete_id']
    user = get_object_or_404(User, athlete_id=athlete_id)
    event = get_object_or_404(Event, identifier=user.event_id)
    
    # Get barcode url    
    barcode_url = "https://service.parkrun.org.uk/runnerSupport/BarcodeImagery/image.php?code=A"+athlete_id

    ### User data ###
    user_data = { 'first_name'  : user.first_names.split()[0], 
                  'full_name'   : user.first_names+" "+user.last_names.upper(), 
                  'event_runs'  : user.event_runs+1, 
                  'total_runs'  : user.total_runs+1, 
                  'barcode_url' : barcode_url }

    ### Event data ###
    
    # If event name to long - create a shorter version
    short_name = event.name
    if len(event.name) > 15:
        short_name = event.name.split()[0]
        
    date = datetime.datetime.now().strftime("%d/%m/%Y")

    event_data = { 'short_name' : short_name, 
                   'long_name'  : event.name,
                   'date'       : date, 
                   'number'     : event.number+1 }

    # Create minimal context
    context = { 'user'     : user_data,
                'event'    : event_data }
    
    # Only add root_url if it has been defined
    if hasattr( settings, 'ROOT_URL' ):
        context['root_url'] = settings.ROOT_URL

    ### Weather data ###
    if event.postcode:
        
        # Find weather based upon first part of postcode
        weather = Weather(event.postcode.split()[0])
        weather.get_weather()
        
        weather_data = { 'icon'     : weather.icon,
                         'postcode' : event.postcode,
                         'text'     : weather.forecast_string, 
                         'temp'     : weather.temperature }
        
        context['weather'] = weather_data

    ### Twitter data ###
    if event.twitter:
        pass

    # Create response
    response = render(request, 'lp_parkrun/edition.html', context)

    # Create ETag
    response['ETag'] = hashlib.sha224(str(user.athlete_id)+date).hexdigest()
    
    return response
开发者ID:lachiemurray,项目名称:lp_parkrun,代码行数:69,代码来源:views.py

示例2: Bot

# 需要导入模块: from weather import Weather [as 别名]
# 或者: from weather.Weather import get_weather [as 别名]

#.........这里部分代码省略.........
            self.thread_queue.queue.clear()
            self.stop_talking()
            self.receive_command()

    def listen(self):
        # stop the clap detector thread when listening for command
        # self.clap_detector.stop()
        self.speak('What can I do for you?')
        # response =
        # self.clap_detector.start()
        return self.voice_parser.listen()

    def receive_command(self):
        # response = self.listen()
        self.speak('What can I do for you?')
        self.speech_q.queue.clear()
        response = None
        while not response:
            response = self.voice_parser.listen()
        print response

        if response == "what's your name":
            self.queue_speech('My name is Faraday')
            self.state = States.Speaking
        elif response == 'who are you':
            self.queue_speech('I am your friend')
            self.state = States.Speaking
        elif response == 'are you a robot':
            self.queue_speech('Yes')
            self.state = States.Speaking

        elif 'weather' in response:
            tomorrow = 'tomorrow' in response
            self.queue_speech(self.weather.get_weather(tomorrow))
            self.state = States.Speaking

        if 'news' in response:
            self.read_news()

        if 'read' in response:
            num_dict = {
                'one': 1,
                'two': 2,
                'three': 3,
                'four': 4,
                'five': 5,
                'six': 6,
                'seven': 7,
                'eight': 8,
                'nine': 9
            }
            arr = response.split(' ')

            for a in ['article', 'articles']:
                if a in arr:
                    num = arr[arr.index(a) + 1]
                    try:
                        index = int(num)
                    except:
                        index = num_dict[num]
                    self.read_full_article(int(index) - 1)

        if 'train' in response:
            self.clap_detector.stop()
            if 'no claps' in response:
                self.clap_detector.train_noclaps(samples=20)
开发者ID:mzw4,项目名称:MorningAssistant,代码行数:70,代码来源:bot.py


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