diff options
author | Al Korgun <alkorgun@gmail.com> | 2012-11-10 22:43:24 +0400 |
---|---|---|
committer | Al Korgun <alkorgun@gmail.com> | 2012-11-10 22:43:24 +0400 |
commit | e1719d7fdebdc28322a1d442172f224f84915038 (patch) | |
tree | e8a2faf8cdfb4d8222113a875937a5d47e680cdf | |
parent | c37dd976d68a5a1b1285655723739251f78e5ff2 (diff) |
command market added (for localization 'ru') and kinopoisk fixed
-rw-r--r-- | expansions/allweb/code.py | 77 | ||||
-rw-r--r-- | expansions/allweb/market.name | 4 | ||||
-rw-r--r-- | expansions/allweb/market.ru | 8 | ||||
-rw-r--r-- | expansions/help/insc.py | 2 |
4 files changed, 83 insertions, 8 deletions
diff --git a/expansions/allweb/code.py b/expansions/allweb/code.py index 80a4042..e21f371 100644 --- a/expansions/allweb/code.py +++ b/expansions/allweb/code.py @@ -255,7 +255,7 @@ class expansion_temp(expansion): Answer(answer, ltype, source, disp) kinoHeaders = { - "Host": "www.kinopoisk.ru", + "Host": "m.kinopoisk.ru", "Accept": "text/html", "Accept-Charset": "cp1251", "Accept-Language": "ru" @@ -274,7 +274,9 @@ class expansion_temp(expansion): limit = 5 else: limit = None - Req = Web("http://www.kinopoisk.ru/level/20/", headers = self.kinoHeaders) + kinoHeaders = self.kinoHeaders.copy() + kinoHeaders["Host"] = "www.kinopoisk.ru" + Req = Web("http://www.kinopoisk.ru/level/20/", headers = kinoHeaders) try: data = Req.get_page(self.UserAgent_Moz) except Web.Two.HTTPError, exc: @@ -307,7 +309,7 @@ class expansion_temp(expansion): else: answer = self.AnsBase[1] elif isNumber(body): - Req = Web("http://m.kinopoisk.ru/movie/%s" % (body), headers = self.kinoHeaders) + Req = Web("http://m.kinopoisk.ru/movie/%s" % (body), headers = self.kinoHeaders.copy()) try: data = Req.get_page(self.UserAgent_Moz) except Web.Two.HTTPError, exc: @@ -331,10 +333,10 @@ class expansion_temp(expansion): answer = self.AnsBase[-1] else: answer = self.AnsBase[5] - else: + elif ls: Req = (body if chr(42) != c1st else body[2:].strip()) Req = Req.encode("cp1251") - Req = Web("http://m.kinopoisk.ru/search/%s" % Web.One.quote_plus(Req), headers = self.kinoHeaders) + Req = Web("http://m.kinopoisk.ru/search/%s" % Web.One.quote_plus(Req), headers = self.kinoHeaders.copy()) try: data = Req.get_page(self.UserAgent_Moz) except Web.Two.HTTPError, exc: @@ -355,6 +357,8 @@ class expansion_temp(expansion): answer = self.AnsBase[-1] else: answer = self.AnsBase[5] + else: + answer = AnsBase[2] else: answer = AnsBase[1] if locals().has_key(Types[12]): @@ -458,7 +462,7 @@ class expansion_temp(expansion): answer = self.AnsBase[1] else: answer = self.AnsBase[1] - else: + elif ls: Req = (body if chr(42) != c1st else body[2:].strip()) Req = Req.encode("utf-8") Req = Web("http://www.imdb.com/find?", [("s", "tt"), ("q", Req)], self.IMDbHeaders) @@ -481,6 +485,8 @@ class expansion_temp(expansion): answer = str.join(chr(10), ls) else: answer = self.AnsBase[5] + else: + answer = AnsBase[2] else: answer = AnsBase[1] if locals().has_key(Types[12]): @@ -806,6 +812,62 @@ class expansion_temp(expansion): answer = AnsBase[1] Answer(answer, ltype, source, disp) + def command_yandex_market(self, ltype, source, body, disp): + if body: + ls = body.split() + c1st = (ls.pop(0)).lower() + if isNumber(c1st): + if ls: + c2st = ls.pop(0) + if isNumber(c2st): + Req = Web("http://m.market.yandex.ru/spec.xml?hid=%d&modelid=%d" % (int(c1st), int(c2st))) + try: + data = Req.get_page(self.UserAgent_Moz) + except Web.Two.HTTPError, exc: + answer = str(exc) + except: + answer = self.AnsBase[0] + else: + data = data.decode("utf-8") + data = get_text(data, "<h2 class=\"b-subtitle\">", "</div>") + if data: + answer = self.decodeHTML(sub_desc(data, (chr(10), ("<li>", chr(10)), ("<h2 class=\"b-subtitle\">", chr(10)*2), ("</h2>", chr(10))))) + else: + answer = self.AnsBase[5] + else: + answer = AnsBase[30] + else: + answer = AnsBase[2] + elif ls: + Req = (body if chr(42) != c1st else body[2:].strip()) + Req = Req.encode("utf-8") + Req = Web("http://m.market.yandex.ru/search.xml?", [("nopreciser", "1"), ("text", Req)]) + try: + data = Req.get_page(self.UserAgent_Moz) + except Web.Two.HTTPError, exc: + answer = str(exc) + except: + answer = self.AnsBase[0] + else: + data = data.decode("utf-8") + comp = compile__("<a href=\"http://m\.market\.yandex\.ru/model\.xml\?hid=(\d+?)&modelid=(\d+?)&show-uid=\d+?\">(.+?)</a>", 16) + list = comp.findall(data) + if list: + Number = itypes.Number() + ls = ["\n[#] [Model Name] (hid & modelid)"] + for hid, modelid, name in list: + if not name.startswith("<img"): + ls.append("%d) %s (%s %s)" % (Number.plus(), self.sub_ehtmls(name), hid, modelid)) + answer = str.join(chr(10), ls) + else: + answer = self.AnsBase[5] + else: + answer = AnsBase[2] + else: + answer = AnsBase[1] + if locals().has_key(Types[12]): + Answer(answer, ltype, source, disp) + commands = ( (command_jc, "jc", 2,), (command_google, "google", 2,), @@ -822,7 +884,8 @@ class expansion_temp(expansion): (command_currency, "currency", 2,), (command_jquote, "jquote", 2,), (command_ithappens, "ithappens", 2,), - (command_gismeteo, "gismeteo", 2,) + (command_gismeteo, "gismeteo", 2,), + (command_yandex_market, "market", 2,) )) Currency_desc = Currency_desc else: diff --git a/expansions/allweb/market.name b/expansions/allweb/market.name new file mode 100644 index 0000000..85ca575 --- /dev/null +++ b/expansions/allweb/market.name @@ -0,0 +1,4 @@ +{
+ "RU": "маркет",
+ "UA": "маркет"
+}
\ No newline at end of file diff --git a/expansions/allweb/market.ru b/expansions/allweb/market.ru new file mode 100644 index 0000000..0bfc015 --- /dev/null +++ b/expansions/allweb/market.ru @@ -0,0 +1,8 @@ +информация о товарах с market.yandex.ru
+маркет [модель]/[[идентификатор_категории] [идентификатор_товара]]/[[*] [модель]]
+*/маркет Sony Xperia S
+бот будет искать "Sony Xperia S"
+*/маркет 91491 7825232
+бот покажет спецификации товара (Sony Xperia S)
+*/маркет * 3310
+бот будет искать товар с названием "3310"
\ No newline at end of file diff --git a/expansions/help/insc.py b/expansions/help/insc.py index ff5b105..408ee44 100644 --- a/expansions/help/insc.py +++ b/expansions/help/insc.py @@ -25,7 +25,7 @@ else: AnsBase_temp = ( "Command '%s' is located in expansion %s", # 0 "%s's access - %d.", # 1 - "\n%s\nSyntax:\n*** %s", # 2 + "\n%s\nSyntax:\n>>> %s", # 2 "\nExamples:", # 3 "Help-file for this command isn't exist...", # 4 "Type 'commands' to get the complete list of commands, type 'help [command]', to know how it works.", # 5 |