Example #1
0
def get_phonetic_symbols(word, headers):
    word = word.strip()
    url = 'http://www.iciba.com/index.php?a=getWordMean&c=search&list=1&word=%s' % word
    try:
        r = requests.get(url, headers=headers)
        res = r.json()
        fb = Feedback()
        for symbol in res['baesInfo']['symbols']:
            means = symbol['parts']
            for mean in means:
                if mean['part']:
                    subtitle = mean['part'] + ' ' + '; '.join(mean['means'])
                else:
                    subtitle = '; '.join(mean['means'])
                if 'ph_en' in symbol and 'ph_am' in symbol:
                    title = '{word} 英:[{en}] 美:[{am}]'.format(
                        word=word, en=symbol['ph_en'], am=symbol['ph_am'])
                elif 'word_symbol' in symbol:
                    title = '{word} 拼音:[{word_symbol}]'.format(
                        word=word, word_symbol=symbol['word_symbol'])
                kwargs = {
                    'title': title,
                    'subtitle': subtitle,
                    'arg': 'http://www.iciba.com/%s' % word,
                }
                fb.addItem(**kwargs)
        fb.output()
    except:
        pass
Example #2
0
def get_suggest(q, headers):
    q = q.strip()
    url = 'http://dict-mobile.iciba.com/interface/index.php?c=word&m=getsuggest&nums=5&client=6&uid=0&is_need_mean=1&word=%s' % q
    try:
        r = requests.get(url, headers=headers)
        res = r.json()
        fb = Feedback()
        for msg in res['message']:
            means = msg['means']
            if not means:
                kwargs = {
                    'title': msg['key'],
                    'autocomplete': '> %s' % msg['key'],
                    'valid': False,
                }
                fb.addItem(**kwargs)
                continue

            for mean in means:
                if mean['part']:
                    subtitle = mean['part'] + ' ' + '; '.join(mean['means'])
                else:
                    subtitle = '; '.join(mean['means'])
                kwargs = {
                    'title': msg['key'],
                    'subtitle': subtitle,
                    'arg': 'http://www.iciba.com/%s' % q,
                    'autocomplete': '> %s' % msg['key'],
                    'valid': False,
                }
                fb.addItem(**kwargs)
        fb.output()
    except:
        pass
def run(q, xq_a_token):
    q = str(q).strip()
    if not q:
        return

    try:
        headers = {
            'Host':
            'xueqiu.com',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.89 Safari/537.36',
        }

        url = 'https://xueqiu.com/v4/stock/quote.json?code=%s' % q
        cookies = {
            'xq_a_token': xq_a_token,
        }
        r = requests.get(url, headers=headers, cookies=cookies)
        res = r.json()
        data = res[q]
        title = '当前价:{current} 涨:{change} 涨幅:{percentage}%'.format(**data)
        link = 'https://xueqiu.com/S/%s' % q
        subtitle = '{name} 昨收:{last_close} 今开:{open} 最高:{high} 最低:{low}'.format(
            **data)

        kwargs = {'title': title, 'subtitle': subtitle, 'arg': link}

        fb = Feedback()
        fb.addItem(**kwargs)
        fb.output()
    except Exception, e:
        print 'EXCEPT:', e
        pass
Example #4
0
def get_phonetic_symbols_new(word, headers):
    word = word.strip()
    # url = "https://dict.iciba.com/dictionary/word/query/web?client=6&key=1000006&timestamp=1628233093905&word=hello&signature=0a78228c59344a8c368f20d47fe6fd2b"
    data = [
        ("client", "6"),
        ("key", "1000006"),
        ("timestamp", str(int(time.time() * 1000))),
        ("word", word),
    ]
    url = "https://dict.iciba.com/dictionary/word/query/web"

    to_sign = url[len("https:"):].replace("//dict.iciba.com", "")
    for k, v in data:
        to_sign += v
    to_sign += "7ece94d9f9c202b0d2ec557dg4r9bc"
    sign = hashlib.md5(to_sign.encode('utf8')).hexdigest()
    data.append(("signature", sign))
    url += "?"
    for k, v in data:
        url += "{k}={v}&".format(k=k, v=v)
    url.rstrip("&")
    r = requests.get(url, headers=headers)
    res = r.json()

    try:
        fb = Feedback()
        msg = res["message"]
        for symbol in msg['baesInfo']['symbols']:
            means = symbol['parts']
            for mean in means:
                if mean['part']:
                    subtitle = mean['part'] + ' ' + '; '.join(mean['means'])
                else:
                    subtitle = '; '.join(mean['means'])
                if 'ph_en' in symbol and 'ph_am' in symbol:
                    title = '{word} 英:[{en}] 美:[{am}]'.format(
                        word=word, en=symbol['ph_en'], am=symbol['ph_am'])
                elif 'word_symbol' in symbol:
                    title = '{word} 拼音:[{word_symbol}]'.format(
                        word=word, word_symbol=symbol['word_symbol'])
                kwargs = {
                    'title': title,
                    'subtitle': subtitle,
                    'arg': 'http://www.iciba.com/%s' % word,
                }
                fb.addItem(**kwargs)
        fb.output()
    except Exception as ex:
        print("EXCEPT:", ex)
def run(q):
    import requests
    from BeautifulSoup import BeautifulSoup as Soup
    from soupselect import select
    from alfred.feedback import Feedback

    fb = Feedback()

    q = q.strip()
    url = 'http://m.lianjia.com/bj/chengjiao/rs%s' % q
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
        'Referer': 'https://m.lianjia.com/bj/sold/search/',
        'Accept':
        'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Accept-Encoding': 'gzip, deflate, sdch, br',
        'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,zh-TW;q=0.2',
        'Cache-Control': 'max-age=0',
        'Connection': 'keep-alive',
        'Upgrade-Insecure-Requests': '1',
    }
    r = requests.get(url, headers=headers)
    r.encoding = 'utf8'
    content = r.text
    soup = Soup(content)
    items = select(soup, 'ul.lists li.pictext')
    for item in items:
        try:
            deal_date = select(item, 'div.item_date')[0].text
            title = select(item, 'div.item_main')[0].text
            desc = select(item, 'span.q_oriention')[0].text
            price = select(item, 'span.price_total')[0].text
            unit_price = select(item, 'span.unit_price')[0].text
            link = select(item, 'a.flexbox')[0]['href']
            kwargs = {
                'title': title + ' ' + price + ' ' + unit_price,
                'subtitle': deal_date + '成交' + ' ' + '位置:' + desc,
                'arg': 'https://m.lianjia.com' + link,
            }
            fb.addItem(**kwargs)
        except:
            pass

    fb.output()
Example #6
0
def search(word):
    feedback = Feedback()
    data = _api(SEARCH_API, params={'word': word})
    if data is None:
        return

    word = data['content']
    pron = data['pron']
    title = "%s [%s]" % (word, pron)
    feedback.addItem(title=title, arg=word)
    for chinese in data['definition'].decode("utf-8").split('\n'):
        feedback.addItem(title=chinese, arg=word)

    if 'en_definitions' in data and data['en_definitions']:
        for type_ in data['en_definitions']:
            for line in data['en_definitions'][type_]:
                title = type_ + ', ' + line
                if not title:
                    continue
                feedback.addItem(title=title, arg=word)
    feedback.output()
Example #7
0
            'update': 'Update config'
        }
        feedback.add_item(title='Internal commands',
                          subtitle=u'Press "↩" to execute selected internal command',
                          valid=False)
        for cmd, desc in internal_cmds.iteritems():
            feedback.add_item(title=cmd, subtitle=desc,
                              arg=':{}'.format(cmd), valid=True)
    else:
        arg = u'{} @ {}'.format(word.decode('utf-8'), dictionary.decode('utf-8'))
        try:
            result = query(dictionary, word)
            if result:
                action = config['keymap']['none'] if config else 'open'
                feedback.add_item(title=result[0],
                                  subtitle=u'Press "↩" to {} or "⌘/⌥/⌃/⇧/fn + ↩" to lookup word in other dicts.'.format(
                                           'view full definition' if action == 'open' else 'pronounce word'),
                                  arg=arg, valid=True)
                for item in result[1:]:
                    feedback.add_item(title=item, arg=u'{} | {}'.format(arg, item), valid=True)
            else:
                feedback.add_item(title='Dict - Lookup Word',
                                  subtitle=u'Word "{}" doesn\'t exist in dict "{}".'.format(
                                           word.decode('utf-8'), dictionary.decode('utf-8')),
                                  arg=arg, valid=True)
        except cndict.DictLookupError, e:
            feedback.add_item(title=word, subtitle='Error: {}'.format(e), arg=arg, valid=True)
else:
    sys.exit(1)
feedback.output()