|
2 | 2 | # アイテム情報取得モジュール |
3 | 3 |
|
4 | 4 | import requests |
5 | | -from bs4 import BeautifulSoup |
6 | | -import simpleDialog |
7 | | -import re |
8 | 5 | import globalVars |
9 | 6 | import constants |
10 | 7 | from logging import getLogger |
|
14 | 11 | log = getLogger("%s.%s" % (constants.LOG_PREFIX, "twitcasting.getItem")) |
15 | 12 |
|
16 | 13 |
|
17 | | -ITEM_BAKU = { |
18 | | - "coin": { |
19 | | - "coin_baku5": 5, |
20 | | - }, |
21 | | -} |
22 | | - |
23 | | - |
24 | 14 | def getItem(screenId): |
25 | 15 | log.debug("Getting items...") |
26 | 16 | if globalVars.app.config["general"]["language"] == "ja-JP": |
@@ -55,60 +45,9 @@ def getItem(screenId): |
55 | 45 | itemId.append("MP") |
56 | 46 | for name, count, id in zip(itemName, itemCount, itemId): |
57 | 47 | if count > 0 or name == "MP": |
58 | | - result.append({"name": name, "count": count, "id": id, "user": getItemPostedUser(screenId, id)}) |
| 48 | + result.append({"name": name, "count": count, "id": id}) |
59 | 49 | return result |
60 | 50 | except Exception as e: |
61 | 51 | log.error(traceback.format_exc()) |
62 | 52 | return None |
63 | 53 |
|
64 | | - |
65 | | -def getItemPostedUser(screenId, itemId): |
66 | | - if itemId == "MP": |
67 | | - return |
68 | | - if globalVars.app.config["general"]["language"] == "ja-JP": |
69 | | - lang = "ja" |
70 | | - else: |
71 | | - lang = "en" |
72 | | - try: |
73 | | - req = requests.get("https://twitcasting.tv/%s/gifts" % (screenId)).text |
74 | | - except: |
75 | | - log.error("Connection failed(getItemPostedUser).") |
76 | | - log.error(traceback.format_exc) |
77 | | - if not hasattr(sys, "frozen"): |
78 | | - import winsound |
79 | | - winsound.Beep(1000, 1000) |
80 | | - traceback.print_exc() |
81 | | - return [] |
82 | | - soup = BeautifulSoup(req, "lxml") |
83 | | - tmp = soup.find("section", {"class": "tw-supporter-gift-history"}) |
84 | | - if tmp is None: |
85 | | - return [] |
86 | | - result = [] |
87 | | - for i in tmp.find_all("div", {"class": "tw-supporter-gift"}): |
88 | | - try: |
89 | | - item = i.find("div", {"class": "tw-supporter-item"}).a["href"] |
90 | | - if re.match("javascript:((giftItem)|(showItemDialog)).*", item): |
91 | | - if "," not in item or "'" not in item: |
92 | | - continue |
93 | | - start = item.index(",") + 3 |
94 | | - end = item.index("'", start) |
95 | | - item = item[start:end] |
96 | | - except Exception as e: |
97 | | - log.error("Failed to get item Id on getItemPostedUser.") |
98 | | - log.error(traceback.format_exc()) |
99 | | - continue |
100 | | - try: |
101 | | - user = i.find("a", {"class": "tw-user-name-icon"})["data-user-id"] |
102 | | - except Exception as e: |
103 | | - log.error("Failed to get user Id on getItemPostedUser.") |
104 | | - log.error(traceback.format_exc()) |
105 | | - continue |
106 | | - if item == itemId: |
107 | | - result.append(user) |
108 | | - # コイン爆対応 |
109 | | - if itemId in ITEM_BAKU: |
110 | | - for j in ITEM_BAKU[itemId]: |
111 | | - if j == item: |
112 | | - log.debug(j) |
113 | | - result += [user] * ITEM_BAKU[itemId][j] |
114 | | - return result |
0 commit comments