Exemplo n.º 1
0
 def show_history(self, name):
     # ディレクトリ
     cache_dir = os.path.join(Common.CACHE_PATH, name)
     if not os.path.isdir(cache_dir):
         os.makedirs(cache_dir)
     # ファイルリスト
     count = 0
     files = sorted(os.listdir(cache_dir),
                    key=lambda message: os.stat(
                        os.path.join(cache_dir, message)).st_mtime,
                    reverse=True)
     for filename in files:
         path = os.path.join(cache_dir, filename)
         if os.path.isfile(path) and not filename.startswith('.'):
             if self.listsize == 0 or count < self.listsize:
                 content = Common.read_file(path)
                 # 日付文字列
                 d = datetime.datetime.fromtimestamp(os.stat(path).st_mtime)
                 weekday = d.weekday()
                 date1 = Common.strftime(
                     d, Common.STR(32901)
                 ) + '(%s)' % Common.STR(32902).split(',')[weekday]
                 time1 = d.strftime('%H:%M:%S')
                 if weekday == 6 or Common.isholiday(
                         d.strftime('%Y-%m-%d')):
                     template = '[COLOR red]%s %s[/COLOR]'
                 elif weekday == 5:
                     template = '[COLOR blue]%s %s[/COLOR]'
                 else:
                     template = '%s %s'
                 fd = template % (date1, time1)
                 # リストアイテム
                 label = '%s  %s' % (fd, content)
                 listitem = xbmcgui.ListItem(label)
                 listitem.setArt({
                     'iconImage': 'DefaultFile.png',
                     'thumb': 'DefaultFile.png'
                 })
                 values = {'action': 'message', 'name': name, 'path': path}
                 query = '%s?%s' % (sys.argv[0], urlencode(values))
                 # コンテクストメニュー
                 menu = []
                 # アドオン設定
                 menu.append((Common.STR(32900),
                              'Addon.OpenSettings(%s)' % Common.ADDON_ID))
                 # 追加
                 listitem.addContextMenuItems(menu, replaceItems=True)
                 xbmcplugin.addDirectoryItem(int(sys.argv[1]), query,
                                             listitem, False)
                 # カウントアップ
                 count += 1
             else:
                 os.remove(path)
     # end of directory
     xbmcplugin.endOfDirectory(int(sys.argv[1]))
Exemplo n.º 2
0
 def update_settings(self):
     # テンプレートを読み込む
     template = Common.read_file(Common.TEMPLATE_FILE)
     # 設定ファイルに書き出すトークンを設定
     keys = list(self.data.keys())
     if len(keys) == 0:
         namelist = 'n/a'
     else:
         namelist = ('|'.join(keys))
         if len(keys) == 1:
             Common.SET('defaultname', keys[0])
     # 設定ファイルを書き出す
     Common.write_file(
         Common.SETTINGS_FILE,
         template.format(tokenname=namelist, tokenname2=namelist))
Exemplo n.º 3
0
def initializeChannel():
    # リセット
    Common.SET('garapon_ch', '')
    # チャンネル情報を取得
    response_body = Request().channel()
    if response_body:
        response_data = json.loads(response_body)
        if response_data['status'] == 1:
            # チャンネル情報をファイルに書き出す
            Common.write_json(Common.CHANNEL_FILE, response_data)
            # チャンネル数を設定
            Common.SET('garapon_ch', '%d channels' % len(response_data['ch_list'].keys()))
            # 設定画面のテンプレートを読み込む
            template = Common.read_file(Common.TEMPLATE_FILE)
            # テンプレートに書き出すジャンル情報
            genre = Genre().getLabel()
            # チャンネル情報とあわせてテンプレートに適用
            source = template.format(
                channel=Channel().getLabel(),
                g0=genre['g0'],
                g00=genre['g00'],
                g01=genre['g01'],
                g02=genre['g02'],
                g03=genre['g03'],
                g04=genre['g04'],
                g05=genre['g05'],
                g06=genre['g06'],
                g07=genre['g07'],
                g08=genre['g08'],
                g09=genre['g09'],
                g10=genre['g10'],
                g11=genre['g11']
            )
            # 設定画面をファイルに書き出す
            Common.write_file(Common.SETTINGS_FILE, source)
            # 完了
            Common.notify('Channel initialized successfully')
            return True
        else:
            Common.log('channel failed', response_body, error=True)
            Common.notify('Channel initialization failed')
            return False
    else:
        Common.log('empty response', error=True)
        Common.notify('Channel initialization failed')
        return False
Exemplo n.º 4
0
 def show_message(self, name, path):
     # 表示内容
     mtime = datetime.datetime.fromtimestamp(
         os.stat(path).st_mtime).strftime('%Y-%m-%d  %H:%M:%S')
     content = '[COLOR green]From:[/COLOR] %s\n' % name
     content += '[COLOR green]Date:[/COLOR] %s\n\n' % mtime
     # ファイル読み込み
     content += Common.read_file(path)
     # テキストビューア
     viewer_id = 10147
     # ウィンドウを開く
     xbmc.executebuiltin('ActivateWindow(%s)' % viewer_id)
     # ウィンドウの用意ができるまで1秒待つ
     xbmc.sleep(1000)
     # ウィンドウへ書き込む
     viewer = xbmcgui.Window(viewer_id)
     viewer.getControl(1).setLabel(mtime)
     viewer.getControl(5).setText(content)