Example #1
0
 def exit(self, msg, clear_cache=True):
     if clear_cache:
         # 删除缓存
         alfred.cache.delete('tasks')
         #! 延迟时间换取缓存 避免对DS的部分操作为完成造成任务状态错误
         forkCacheProcess(10)
     alfred.exit(msg)
Example #2
0
def openURL():
    try:
        page = b64decode(alfred.argv(2))
        subprocess.check_output('open "{}"'.format(page), shell=True)
    except Exception, e:
        alfred.log(e)
        alfred.exit('出错啦')
Example #3
0
def showLive():
    favs = getFavChannels()
    if not favs: alfred.exit()
    feedback = alfred.Feedback()
    for channel in favs:
        chl_title = getChannelTitle(channel)
        if not chl_title:
            continue
        cur, next = getCurrentAndNextProgram(channel)
        title = '{}'.format(chl_title)
        if cur:
            title = '{} 正在播放: {}'.format(chl_title, cur['show'])
        subtitle = ''
        if next:
            subtitle = '下一个节目: {time} {show}'.format(**next)
        feedback.addItem(
            title           = title,
            subtitle        = subtitle,
            autocomplete    = 'epg {}'.format(channel),
            valid           = False
            )
    feedback.addItem(
        title               = '显示所有电视频道',
        autocomplete        = 'all',
        valid               = False
        )
    feedback.addItem(
        title               = '显示收藏的电视频道',
        autocomplete        = 'fav',
        valid               = False
        )
    feedback.output()
Example #4
0
def toggleAppIconShowing():
    sub = alfred.argv(2)
    if not sub or sub not in ['enable', 'disable']:
        alfred.exit('argument error')
    v = True if sub=='enable' else False
    alfred.config.set(app_icon_show = v)
    alfred.exit('App Icon Showing {}'.format('Enabled' if v else 'Disabled'))
Example #5
0
def downloadWithDS():
    try:
        link = b64decode(alfred.argv(2))
        alfred.query('ds create {}'.format(link))
    except Exception, e:
        alfred.log(e)
        alfred.exit('出错啦')
Example #6
0
def changeCountry():
    sub = alfred.argv(2)
    if not sub or sub not in country_currency.keys():
        return
    alfred.config.set(country=sub)
    alfred.cache.clean()
    alfred.exit('Country/Currency has changed to {}.'.format(country_currency[sub]))
Example #7
0
    def run(self):
        cmd = alfred.argv(1)
        if not cmd:
            return self.showDefaultList()
        cmd = cmd.lower()
        for page in default_pages:
            if cmd == page['cmd']:
                url = self.getUrl(page['page'])
                self.showAppsFromPage(url)
                alfred.exit()

        self.tryShowMoreApps()

        if cmd.startswith('search'):
            cmd = 'search'
        if cmd.startswith('more-apps-'):
            cmd = 'more-apps'

        cmd_map = {
            'search'            : lambda: self.search(),
            'wishlist'          : lambda: self.showWishList(),
            'setting'           : lambda: self.showSettings(),
            'more-apps'         : lambda: self.showMoreApps(),
            'change-country'    : lambda: self.showCountries()
        }
        if cmd in cmd_map.keys():
            return cmd_map[cmd]()
        return self.showDefaultList()
Example #8
0
 def exit(self, msg, clear_cache=True):
     if clear_cache:
         # 删除缓存
         self.cache.delete('tasks')
         #! 延迟时间换取缓存 避免对DS的部分操作为完成造成任务状态错误
         forkCacheProcess(10)
     alfred.exit(msg)
Example #9
0
    def run(self):
        cmd = alfred.argv(1)
        if not cmd:
            return self.showDefaultList()
        cmd = cmd.lower()
        for page in default_pages:
            if cmd == page['cmd']:
                url = self.getUrl(page['page'])
                self.showAppsFromPage(url)
                alfred.exit()

        self.tryShowMoreApps()

        if cmd.startswith('search'):
            cmd = 'search'
        if cmd.startswith('more-apps-'):
            cmd = 'more-apps'

        cmd_map = {
            'search': lambda: self.search(),
            'wishlist': lambda: self.showWishList(),
            'setting': lambda: self.showSettings(),
            'more-apps': lambda: self.showMoreApps(),
            'change-country': lambda: self.showCountries()
        }
        if cmd in cmd_map.keys():
            return cmd_map[cmd]()
        return self.showDefaultList()
Example #10
0
def openLink():
    try:
        links = alfred.argv(2).strip().split(',')
        open_store_link = alfred.config.get('open_store_link', True)
        link = links[0] if open_store_link else links[1]
        subprocess.check_output(['open', link])
    except Exception, e:
        alfred.exit('something error.')
Example #11
0
    def showAllSetting(self):
        feedback = alfred.Feedback()
        current_auth_info = "{}:{}@{}".format(
            alfred.config.get("usr", ""),
            "".join(["*" for s in alfred.config.get("pwd", "")]),
            alfred.config.get("host", ""),
        )
        feedback.addItem(
            title="Authorization",
            subtitle="login information. current: {}".format(current_auth_info),
            autocomplete=" auth ",
            valid=False,
        )

        # 未设置账户信息等登陆信息
        if not self.isAccountInfoExists():
            feedback.output()
            alfred.exit()  # 未授权不显示其它的设置信息,退出

        # 清理缓存
        feedback.addItem(title="Clean", subtitle="cache, login session ...", arg="clean")

        config = self.getCache("dsconfig")
        # pprint(data)
        if not config:
            feedback.addItem(title="Fetch download station config failed.")
        else:
            # eMule的禁用与启用
            emule_enabled = config["emule_enabled"]
            feedback.addItem(
                title="Disable eMule" if emule_enabled else "Enable eMule",
                arg="server-config emule_enabled {}".format("false" if emule_enabled else "true"),
            )
            # 计划的启用与禁用
            schedule_enabled = config["schedule_enabled"]
            feedback.addItem(
                title="Disable Download Schedule" if schedule_enabled else "Enable Download Schedule",
                arg="schedule-config enabled {}".format("false" if schedule_enabled else "true"),
            )
            schedule_emule_enabled = config["schedule_emule_enabled"]
            feedback.addItem(
                title="Disable eMule Download Schedule" if schedule_emule_enabled else "Enable eMule Download Schedule",
                arg="schedule-config emule_enabled {}".format("false" if schedule_emule_enabled else "true"),
            )

            # 其它配置信息
            emule_speed = "eMule: {emule_max_download}/{emule_max_upload}".format(**config)
            bt_speed = "BT: {bt_max_download}/{bt_max_upload}".format(**config)
            http_speed = "FTP/HTTP: {http_max_download}".format(**config)
            nzb_speend = "NZB: {nzb_max_download}".format(**config)
            feedback.addItem(
                title="{}   {}   {}   {}".format(emule_speed, bt_speed, http_speed, nzb_speend),
                subtitle="Max download/upload speed in KB/s(0 means unlimited)",
                arg="open-browser",  # 打开网页端
            )
        feedback.output()
Example #12
0
 def __init__(self):
     super(DSCache, self).__init__()
     if not self.isAccountInfoExists():
         alfred.exit()
     self.cmds = {
         'all': lambda: self.cacheAll(),
         'tasks': lambda: self.cacheTasks(),
         'info': lambda: self.cacheDSInfo(),
         'config': lambda: self.cacheDSConfig()
     }
Example #13
0
 def __init__(self):
     super(DSCache, self).__init__()
     if not self.isAuthorized():
         alfred.exit()
     self.cmds = {
         'all'       : lambda: self.cacheAll(),
         'tasks'     : lambda: self.cacheTasks(),
         'info'      : lambda: self.cacheDSInfo(),
         'config'    : lambda: self.cacheDSConfig()
     }
Example #14
0
def postRecord(to_save):
    com_code = alfred.argv(2)
    post_id = alfred.argv(3)
    if com_code is None or post_id is None:
        alfred.exit('出错了,参数错误。')
    if to_save:
        express.savePost(com_code, post_id)
    else:
        express.delPost(com_code, post_id)
    alfred.exit('运单 {} 已{}'.format(post_id, '保存' if to_save else '删除'))
Example #15
0
def postRecord(to_save):
    com_code = alfred.argv(2)
    post_id = alfred.argv(3)
    if com_code is None or post_id is None:
        alfred.exit('出错了,参数错误。')
    if to_save:
        express.savePost(com_code, post_id)
    else:
        express.delPost(com_code, post_id)
    alfred.exit('运单 {} 已{}'.format(post_id, '保存' if to_save else '删除'))
Example #16
0
def main():
    cmds = {
        'open-url'          : lambda: openURL(),
        'copy-to-clipboard' : lambda: copyToClipboard(),
        'download-with-ds'  : lambda: downloadWithDS()
    }
    cmd = alfred.argv(1)
    if not cmd or cmd.lower() not in cmds.keys():
        alfred.exit('出错啦')
    cmds[cmd]();
Example #17
0
def copyToClipboard():
    try:
        word = b64decode(alfred.argv(2))
        pb = NSPasteboard.generalPasteboard()
        pb.clearContents()
        a = NSArray.arrayWithObject_(word)
        pb.writeObjects_(a)
        alfred.exit('已拷贝地址到剪切板')
    except Exception, e:
        alfred.log(e)
        alfred.exit('出错啦')
Example #18
0
def main():
    cmds = {
        'open-url'  : lambda: openURL(),
        'save-post' : lambda: postRecord(True),
        'del-post'  : lambda: postRecord(False),
        'clear-checked-post' : lambda: clearCheckedPost(),
        'remark-setting' : lambda: setRemark()
    }
    cmd = alfred.argv(1)
    if not cmd or cmd.lower() not in cmds.keys():
        alfred.exit('无效参数。')
    cmds[cmd]();
Example #19
0
def main():
    cmds = {
        'open-url': lambda: openURL(),
        'save-post': lambda: postRecord(True),
        'del-post': lambda: postRecord(False),
        'clear-checked-post': lambda: clearCheckedPost(),
        'remark-setting': lambda: setRemark()
    }
    cmd = alfred.argv(1)
    if not cmd or cmd.lower() not in cmds.keys():
        alfred.exit('无效参数。')
    cmds[cmd]()
Example #20
0
def main():
    cmd = alfred.argv(1)
    cmd_map = {
        'set-username'      : lambda: setUsername(),
        'open-link'         : lambda: openLink(),
        'clean'             : lambda: clearCache(),
        'app-icon-showing'  : lambda: toggleAppIconShowing(),
        'change-country'    : lambda: changeCountry(),
        'switch-link-open-type' : lambda: switchLinkOpenType()
    }
    if not cmd or cmd.lower() not in cmd_map.keys():
        alfred.exit()
    cmd_map[cmd]()
Example #21
0
 def tryShowMoreApps(self):
     sub = alfred.argv(1)
     for t in ['mac', 'ipad', 'iphone']:
         for item in more_apps_pages:
             title = item['title'].format(**more_apps_page_type[t])
             cmd = '-'.join(title.lower().split(' '))
             if sub != cmd:
                 continue
             platform = more_apps_page_type[t]['platform']
             device = more_apps_page_type[t]['device']
             page_url = self.getUrl(platform, device, item['page'])
             self.showAppsFromPage(page_url)
             alfred.exit()
Example #22
0
 def tryShowMoreApps(self):
     sub = alfred.argv(1)
     for t in ['mac', 'ipad', 'iphone']:
         for item in more_apps_pages:
             title = item['title'].format(**more_apps_page_type[t])
             cmd = '-'.join(title.lower().split(' '))
             if sub != cmd:
                 continue
             platform = more_apps_page_type[t]['platform']
             device = more_apps_page_type[t]['device']
             page_url = self.getUrl(platform, device, item['page'])
             self.showAppsFromPage(page_url)
             alfred.exit()
Example #23
0
def main():
    try:
        w = ' '.join(sys.argv[1:]).strip()
        ret = cndict.translate(w)
        translation = ret.get('translation', [])
        translation = ';'.join(translation) if translation else ''
        phonetic = ret.get('basic', {}).get('phonetic')
        if not translation:
            raise Exception('无法翻译')
        if phonetic:
            print('[{}]'.format(phonetic))
        print(translation)
    except Exception, e:
        alfred.exit('出错了,{}'.format(e), 1)
Example #24
0
def toggleFavChannel():
    channel = alfred.argv(2)
    channel_title = getChannelTitle(channel)
    if not channel_title:
        return
    favs = getFavChannels()
    if isChannelFaved(channel):
        favs = filter(lambda f: f != channel, favs)
        alfred.config.set(fav=favs)
        alfred.exit('频道 {} 已被取消收藏'.format(channel_title))
    else:
        favs.append(channel)
        alfred.config.set(fav=favs)
        alfred.exit('已收藏频道 {}'.format(channel_title))
Example #25
0
def toggleFavChannel():
    channel = alfred.argv(2)
    channel_title = getChannelTitle(channel)
    if not channel_title:
        return
    favs = getFavChannels()
    if isChannelFaved(channel):
        favs = filter(lambda f: f!=channel, favs)
        alfred.config.set(fav=favs)
        alfred.exit('频道 {} 已被取消收藏'.format(channel_title))
    else:
        favs.append(channel)
        alfred.config.set(fav=favs)
        alfred.exit('已收藏频道 {}'.format(channel_title))
Example #26
0
def main():
    try:
        w = ' '.join(sys.argv[1:]).strip()
        ret = cndict.translate(w)
        translation = ret.get('translation', [])
        translation = ';'.join(translation) if translation else ''
        phonetic = ret.get('basic', {}).get('phonetic')
        if not translation:
            raise Exception('无法翻译')
        if phonetic:
            print('[{}]'.format(phonetic))
        print(translation)
    except Exception, e:
        alfred.exit('出错了,{}'.format(e), 1)
Example #27
0
def toggleBluetooth():
    bundle = objc.loadBundle('IOBluetooth', globals(), bundle_path=objc.pathForFramework('/System/Library/Frameworks/IOBluetooth.framework'))
    if not bundle:
        alfred.exit('Toggle Bluetooth fail. initFrameworkWrapper error')
    fs = [('IOBluetoothPreferenceGetControllerPowerState', 'oI'),('IOBluetoothPreferenceSetControllerPowerState','vI')]
    ds = {}
    objc.loadBundleFunctions(bundle, ds, fs)
    for (name, handle) in fs:
        if not name in ds:
            alfred.exit('Toggle Bluetooth fail. failed to load: {}'.format(name))
    if ds['IOBluetoothPreferenceGetControllerPowerState']() == 1:
        ds['IOBluetoothPreferenceSetControllerPowerState'](0)
        alfred.exit('Bluetooth Disabled.')
    else:
        ds['IOBluetoothPreferenceSetControllerPowerState'](1)
        alfred.exit('Bluetooth Enable.')
Example #28
0
def setAccount():
    usr = alfred.argv(2)
    pwd = alfred.argv(3)
    if not usr or not pwd:
        alfred.exit('信息不完整。')
    alfred.config.set(usr=usr, pwd=pwd)
    if yyets.login():
        alfred.exit('账户信息已保存,并成功登陆。')
    alfred.exit('账户信息已保存,但尝试登陆失败。')
Example #29
0
 def saveLyricToiTunes(self):
     lrc = self.getCleanLyricContent()
     if not lrc:
         alfred.exit('Fail: lyric is non-existent.')
     # lrc = 'test'
     res = subprocess.check_output('osascript itunes.applescript lyric "{}"'.format(lrc), shell=True)
     info = map(lambda s: s.strip(), res.split(','))
     code = int(info[0])
     if code != 0:
         alfred.exit('Fail: {}'.format(info[1]))
     alfred.exit('Lyric saved to {} - {}.'.format(info[1], info[2]))
Example #30
0
 def saveLyricToiTunes(self):
     lrc = self.getCleanLyricContent()
     if not lrc:
         alfred.exit('Fail: lyric is non-existent.')
     # lrc = 'test'
     res = subprocess.check_output(
         'osascript itunes.applescript lyric "{}"'.format(lrc), shell=True)
     info = map(lambda s: s.strip(), res.split(','))
     code = int(info[0])
     if code != 0:
         alfred.exit('Fail: {}'.format(info[1]))
     alfred.exit('Lyric saved to {} - {}.'.format(info[1], info[2]))
Example #31
0
def setAccount():
    usr = alfred.argv(2)
    pwd = alfred.argv(3)
    if not usr or not pwd:
        alfred.exit('信息不完整。')
    alfred.config.set(
        usr = usr,
        pwd = pwd
    )
    if yyets.login():
        alfred.exit('账户信息已保存,并成功登陆。')
    alfred.exit('账户信息已保存,但尝试登陆失败。')
Example #32
0
 def download(self):
     lrc_id = alfred.argv(2)
     info = self.getLyricInfoFromCache(lrc_id)
     if info is None:
         alfred.exit('Lyric is non-existent.')
     res, data = self.fetchLyricContent(lrc_id)
     if not res:
         alfred.exit(data)
     try:
         filename = '{title}.lrc' if not info['artist'] else '{artist} - {title}.lrc'
         dl_path = os.path.expanduser('~/Downloads')
         dl_path = os.path.join(dl_path, filename.format(**info))
         with codecs.open(dl_path, 'w', 'utf-8') as f:
             f.write(data)
         if os.path.exists(dl_path):
             subprocess.check_output(['open', os.path.dirname(dl_path)])
         alfred.exit('Lyric downloaded.')
     except Exception, e:
         alfred.exit('Download lyric fail. {}'.format(e))
Example #33
0
 def download(self):
     lrc_id = alfred.argv(2)
     info = self.getLyricInfoFromCache(lrc_id)
     if info is None:
         alfred.exit('Lyric is non-existent.')
     res, data = self.fetchLyricContent(lrc_id)
     if not res:
         alfred.exit(data)
     try:
         filename = '{title}.lrc' if not info[
             'artist'] else '{artist} - {title}.lrc'
         dl_path = os.path.expanduser('~/Downloads')
         dl_path = os.path.join(dl_path, filename.format(**info))
         with codecs.open(dl_path, 'w', 'utf-8') as f:
             f.write(data)
         if os.path.exists(dl_path):
             subprocess.check_output(['open', os.path.dirname(dl_path)])
         alfred.exit('Lyric downloaded.')
     except Exception, e:
         alfred.exit('Download lyric fail. {}'.format(e))
Example #34
0
def toggleBluetooth():
    bundle = objc.loadBundle(
        'IOBluetooth',
        globals(),
        bundle_path=objc.pathForFramework(
            '/System/Library/Frameworks/IOBluetooth.framework'))
    if not bundle:
        alfred.exit('Toggle Bluetooth fail. initFrameworkWrapper error')
    fs = [('IOBluetoothPreferenceGetControllerPowerState', 'oI'),
          ('IOBluetoothPreferenceSetControllerPowerState', 'vI')]
    ds = {}
    objc.loadBundleFunctions(bundle, ds, fs)
    for (name, handle) in fs:
        if not name in ds:
            alfred.exit(
                'Toggle Bluetooth fail. failed to load: {}'.format(name))
    if ds['IOBluetoothPreferenceGetControllerPowerState']() == 1:
        ds['IOBluetoothPreferenceSetControllerPowerState'](0)
        alfred.exit('Bluetooth Disabled.')
    else:
        ds['IOBluetoothPreferenceSetControllerPowerState'](1)
        alfred.exit('Bluetooth Enable.')
Example #35
0
    def showAllSetting(self):
        feedback = alfred.Feedback()
        current_auth_info = '{}:{}@{}'.format(
            self.config.get('usr', ''),
            ''.join(['*' for s in self.config.get('pwd', '')]),
            self.config.get('host', '')
            )
        feedback.addItem(
            title           = 'Authorization',
            subtitle        = 'login information. current: {}'.format(current_auth_info),
            autocomplete    = ' auth ',
            valid           = False
            )

        # 未设置账户信息等登陆信息
        if not self.isAuthorized():
            feedback.output()
            alfred.exit() # 未授权不显示其它的设置信息,退出

        # 清理缓存
        feedback.addItem(
            title       = 'Clean',
            subtitle    = 'cache, login session ...',
            arg         = 'clean'
            )
        
        config = self.getCache('dsconfig')
        # pprint(data)
        if not config:
            feedback.addItem(
                title       = 'Fetch download station config failed.',
                subtitle    = '{}'.format(data)
                )
        else:
            # eMule的禁用与启用
            emule_enabled = config['emule_enabled']
            feedback.addItem(
                title       = 'Disable eMule' if emule_enabled else 'Enable eMule',
                arg         = 'server-config emule_enabled {}'.format('false' if emule_enabled else 'true')
                )
            # 计划的启用与禁用
            schedule_enabled = config['schedule_enabled']
            feedback.addItem(
                title       = 'Disable Download Schedule' if schedule_enabled else 'Enable Download Schedule',
                arg         = 'schedule-config enabled {}'.format('false' if schedule_enabled else 'true')
                )
            schedule_emule_enabled = config['schedule_emule_enabled']
            feedback.addItem(
                title       = 'Disable eMule Download Schedule' if schedule_emule_enabled else 'Enable eMule Download Schedule',
                arg         = 'schedule-config emule_enabled {}'.format('false' if schedule_emule_enabled else 'true')
                )

            # 其它配置信息
            emule_speed = 'eMule: {emule_max_download}/{emule_max_upload}'.format(**config)
            bt_speed = 'BT: {bt_max_download}/{bt_max_upload}'.format(**config)
            http_speed = 'FTP/HTTP: {http_max_download}'.format(**config)
            nzb_speend = 'NZB: {nzb_max_download}'.format(**config)
            feedback.addItem(
                title       = '{}   {}   {}   {}'.format(emule_speed, bt_speed, http_speed, nzb_speend),
                subtitle    = 'Max download/upload speed in KB/s(0 means unlimited)',
                arg         = 'open-browser'    # 打开网页端
                )
        feedback.output()
Example #36
0
def doShellScript(script):
    res = subprocess.check_output(script, shell=True)
    alfred.exit(res.strip())
Example #37
0
 def outputCleanContent(self):
     alfred.exit(self.getCleanLyricContent())
Example #38
0
def clearCheckedPost():
    express.clearCheckedPost()
    alfred.exit('所有已签收的运单已被清除。')
Example #39
0
def clearCache():
    alfred.cache.clean()
    alfred.exit('All cache cleared.')
Example #40
0
def doShellScript(script):
    res = subprocess.check_output(script, shell=True)
    alfred.exit(res.strip())
Example #41
0
def setRemark():
    com_code = alfred.argv(2)
    post_id = alfred.argv(3)
    remark = ' '.join(sys.argv[4:])
    ret = express.changePostRemark(com_code, post_id, remark)
    alfred.exit('运单 {} 备注已更改。'.format(post_id) if ret else '出错了。')
Example #42
0
 def outputCleanContent(self):
     alfred.exit(self.getCleanLyricContent())
Example #43
0
def setUsername():
    usr = alfred.argv(2)
    if not usr:
        alfred.exit('no username found.')
    alfred.config.set(username = usr.strip())
    alfred.exit('AppShopper username has setted.')
Example #44
0
def setRemark():
    com_code = alfred.argv(2)
    post_id = alfred.argv(3)
    remark = ' '.join(sys.argv[4:])
    ret = express.changePostRemark(com_code, post_id, remark)
    alfred.exit('运单 {} 备注已更改。'.format(post_id) if ret else '出错了。')
Example #45
0
def switchLinkOpenType():
    alfred.cache.clean()
    open_store_link = alfred.config.get('open_store_link', True)
    new_value = False if open_store_link else True
    alfred.config.set(open_store_link=new_value)
    alfred.exit('{} link will be opened.'.format('iTunes' if new_value else 'AppShopper'))
Example #46
0
    def showAllSetting(self):
        feedback = alfred.Feedback()
        current_auth_info = '{}:{}@{}'.format(
            alfred.config.get('usr', ''),
            ''.join(['*' for s in alfred.config.get('pwd', '')]),
            alfred.config.get('host', '')
            )
        feedback.addItem(
            title           = 'Authorization',
            subtitle        = 'login information. current: {}'.format(current_auth_info),
            autocomplete    = ' auth ',
            valid           = False
            )

        # 未设置账户信息等登陆信息
        if not self.isAccountInfoExists():
            feedback.output()
            alfred.exit() # 未授权不显示其它的设置信息,退出

        # 清理缓存
        feedback.addItem(
            title       = 'Clean',
            subtitle    = 'cache, login session ...',
            arg         = 'clean'
            )
        
        config = self.getCache('dsconfig')
        # pprint(data)
        if not config:
            feedback.addItem(
                title       = 'Fetch download station config failed.'
                )
        else:
            # eMule的禁用与启用
            emule_enabled = config['emule_enabled']
            feedback.addItem(
                title       = 'Disable eMule' if emule_enabled else 'Enable eMule',
                arg         = 'server-config emule_enabled {}'.format('false' if emule_enabled else 'true')
                )
            # 计划的启用与禁用
            schedule_enabled = config['schedule_enabled']
            feedback.addItem(
                title       = 'Disable Download Schedule' if schedule_enabled else 'Enable Download Schedule',
                arg         = 'schedule-config enabled {}'.format('false' if schedule_enabled else 'true')
                )
            schedule_emule_enabled = config['schedule_emule_enabled']
            feedback.addItem(
                title       = 'Disable eMule Download Schedule' if schedule_emule_enabled else 'Enable eMule Download Schedule',
                arg         = 'schedule-config emule_enabled {}'.format('false' if schedule_emule_enabled else 'true')
                )

            # 其它配置信息
            emule_speed = 'eMule: {emule_max_download}/{emule_max_upload}'.format(**config)
            bt_speed = 'BT: {bt_max_download}/{bt_max_upload}'.format(**config)
            http_speed = 'FTP/HTTP: {http_max_download}'.format(**config)
            nzb_speend = 'NZB: {nzb_max_download}'.format(**config)
            feedback.addItem(
                title       = '{}   {}   {}   {}'.format(emule_speed, bt_speed, http_speed, nzb_speend),
                subtitle    = 'Max download/upload speed in KB/s(0 means unlimited)',
                arg         = 'open-browser'    # 打开网页端
                )
        feedback.output()
Example #47
0
import os
import alfred
import logging

#s = os.popen('curl --socks5 localhost:1081 -s http://tomcat:5000/api/realtime_status').read()

opened_1080 = os.popen('ps aux | grep ssh.*1080 | grep -v grep').read()
opened_1081 = os.popen('ps aux | grep ssh.*1081 | grep -v grep').read()

cmds = []
ports = []
if opened_1080 == '':
  cmds.append('ssh -D 1080 -N -f -p 8022 tomcat.hvps.tk')
  ports.append('1080')

if opened_1081 == '':
  cmds.append('ssh -D 1081 -N -f eagle.hvps.tk')
  ports.append('1081')

if cmds:
  cmd = ' & '.join(cmds)
  alfred.log(cmd)
  os.system(cmd)
  alfred.log('p2')
  alfred.exit('proxies on port(s): ' + ', '.join(ports))
else:
  alfred.exit('all proxies are running')