Pythonista 達の熱き闘いが,
今,始まる...!!
[2010/12/22 21:12:55] 登録
■ 名前
■ ステータス
HP | SP | 攻撃力 | 集中力 | 防御力 | 素早さ | 運 |
---|---|---|---|---|---|---|
340 | 46 | 52 | 56 | 10 | 2 | 9 |
■ 必殺技
名前 | タイプ | レベル | 消費 SP |
---|---|---|---|
スカルスティング | MultiAttackType | 3 | 20 |
リバーサイドドロップ | SuicideAttackType | 2 | 9 |
■ コード
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) 2010 by Shyouzou Sugitani <shy@users.sourceforge.jp> # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License (version 2) as # published by the Free Software Foundation. It is distributed in the # hope that it will be useful, but WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the GNU General Public License for more details. # import os import sys import socket import random try: import pywapi except: raise SystemExit, 'Need pywapi - Python Weather API from http://code.google.com/p/python-weather-api/.' try: from ninix.plugin import send_script except: send_script = None def choice_city(): countries = pywapi.get_countries_from_google('ja') country = random.choice(countries) iso_code = country['iso_code'] cities = pywapi.get_cities_from_google(iso_code, 'ja') while len(cities) < 1: country = random.choice(countries) iso_code = country['iso_code'] cities = pywapi.get_cities_from_google(iso_code, 'ja') city = random.choice(cities) return country, city def main(): error_message = r'\1あっ,\w4エラーになってしもたやん.\n\w4Googleはん, \w2おとうはんといっしょで\w2かいしょなしやん.\w9\0!?\e' country, city = choice_city() data = pywapi.get_weather_from_google( ''.join((',,,', city['latitude_e6'], ',', city['longitude_e6'])), 'ja') if len(sys.argv) < 2: result = r'\1今の' conditions = data['current_conditions'] # XXX elif sys.argv[1] == 'currnet': result = r'\1今の' conditions = data['current_conditions'] elif sys.argv[1] == 'today': if len(data['forecasts']) < 1: return error_message result = r'\1今日の' conditions = data['forecasts'][0] elif sys.argv[1] == 'tomorrow': if len(data['forecasts']) < 2: return error_message result = r'\1明日の' conditions = data['forecasts'][1] else: result = r'\1今の' conditions = data['current_conditions'] # XXX location = ''.join((unicode(country['name']).encode('utf-8'), ' ', unicode(city['name']).encode('utf-8'))) result = ''.join((result, location, 'の')) if 'condition' not in conditions: return error_message else: condition = unicode(conditions['condition']).encode('utf-8') result = ''.join((result, r'てんきはな, \w9')) result = ''.join((result, condition, r'やん.\n\w9')) if 'temp_c' in conditions: try: temp_c = int(conditions['temp_c']) except: return error_message else: if temp_c <= 15: result = ''.join((result, r'さむいやん.')) elif 15 < temp_c < 25: result = ''.join((result, r'すごしやすそうやん.')) elif temp_c >= 25: result = ''.join((result, r'あつそうやん.')) elif 'high' in conditions and 'low' in conditions: try: high = int(conditions['high']) low = int(conditions['low']) except: return error_message else: if high - low > 10: result = ''.join((result, r'いやー,\w4 あつなったりさむなったり,\w2 きついわぁ.')) else: result = ''.join((result, r'あつささむさもひがんまでやん.')) result = ''.join((result, r'\0!?\e')) return result if __name__ == "__main__": result = main() if send_script is not None: send_script('otenkiyan.py', result) else: print result