Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
firmianay committed May 12, 2023
1 parent 536e7ae commit bced218
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
34 changes: 17 additions & 17 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from datetime import datetime
from pyrate_limiter import Duration, Limiter, RequestRate

from utils import Color
from utils import *

__all__ = ["feishuBot", "wecomBot", "dingtalkBot", "qqBot", "telegramBot", "mailBot"]
today = datetime.now().strftime("%Y-%m-%d")
Expand Down Expand Up @@ -46,9 +46,9 @@ def send(self, text_list: list):
r = requests.post(url=url, headers=headers, data=json.dumps(data), proxies=self.proxy)

if r.status_code == 200:
Color.print_success('[+] feishuBot 发送成功')
console.print('[+] feishuBot 发送成功', style='bold green')
else:
Color.print_failed('[-] feishuBot 发送失败')
console.print('[-] feishuBot 发送失败', style='bold red')
print(r.text)

def send_markdown(self, text):
Expand Down Expand Up @@ -88,9 +88,9 @@ def send(self, text_list: list):
r = requests.post(url=url, headers=headers, data=json.dumps(data), proxies=self.proxy)

if r.status_code == 200:
Color.print_success('[+] wecomBot 发送成功')
console.print('[+] wecomBot 发送成功', style='bold green')
else:
Color.print_failed('[-] wecomBot 发送失败')
console.print('[-] wecomBot 发送失败', style='bold red')
print(r.text)


Expand Down Expand Up @@ -123,9 +123,9 @@ def send(self, text_list: list):
r = requests.post(url=url, headers=headers, data=json.dumps(data), proxies=self.proxy)

if r.status_code == 200:
Color.print_success('[+] dingtalkBot 发送成功')
console.print('[+] dingtalkBot 发送成功', style='bold green')
else:
Color.print_failed('[-] dingtalkBot 发送失败')
console.print('[-] dingtalkBot 发送失败', style='bold red')
print(r.text)


Expand Down Expand Up @@ -160,11 +160,11 @@ def send(self, text_list: list):
try:
r = requests.post(f'{self.server}/send_group_msg?group_id={id}&&message={text}')
if r.status_code == 200:
Color.print_success(f'[+] qqBot 发送成功 {id}')
console.print(f'[+] qqBot 发送成功 {id}', style='bold green')
else:
Color.print_failed(f'[-] qqBot 发送失败 {id}')
console.print(f'[-] qqBot 发送失败 {id}', style='bold red')
except Exception as e:
Color.print_failed(f'[-] qqBot 发送失败 {id}')
console.print(f'[-] qqBot 发送失败 {id}', style='bold red')
print(e)

def start_server(self, qq_id, qq_passwd, timeout=60):
Expand All @@ -182,14 +182,14 @@ def start_server(self, qq_id, qq_passwd, timeout=60):
while True:
try:
requests.get(self.server)
Color.print_success('[+] qqBot 启动成功')
console.print('[+] qqBot 启动成功', style='bold green')
return True
except Exception as e:
time.sleep(1)

if time.time() > timeout:
qqBot.kill_server()
Color.print_failed('[-] qqBot 启动失败')
console.print('[-] qqBot 启动失败', style='bold red')
return False

@classmethod
Expand Down Expand Up @@ -245,9 +245,9 @@ def send(self, text: str):

try:
self.smtp.sendmail(self.sender, self.receiver.split(','), msg.as_string())
Color.print_success('[+] mailBot 发送成功')
console.print('[+] mailBot 发送成功', style='bold green')
except Exception as e:
Color.print_failed('[+] mailBot 发送失败')
console.print('[+] mailBot 发送失败', style='bold red')
print(e)


Expand All @@ -265,7 +265,7 @@ def test_connect(self):
self.bot.get_me()
return True
except Exception as e:
Color.print_failed('[-] telegramBot 连接失败')
console.print('[-] telegramBot 连接失败', style='bold red')
return False

@staticmethod
Expand All @@ -288,7 +288,7 @@ def send(self, text_list: list):
for id in self.chat_id:
try:
self.bot.send_message(chat_id=id, text=text, parse_mode='HTML')
Color.print_success(f'[+] telegramBot 发送成功 {id}')
console.print(f'[+] telegramBot 发送成功 {id}', style='bold green')
except Exception as e:
Color.print_failed(f'[-] telegramBot 发送失败 {id}')
console.print(f'[-] telegramBot 发送失败 {id}', style='bold red')
print(e)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rich
requests
feedparser
pyfiglet
colorama
schedule
pyyaml
python-telegram-bot
Expand Down
25 changes: 5 additions & 20 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
import pprint
from colorama import Fore


class Color:
@staticmethod
def print_focus(data: str):
print(Fore.YELLOW+data+Fore.RESET)

@staticmethod
def print_success(data: str):
print(Fore.LIGHTGREEN_EX+data+Fore.RESET)

@staticmethod
def print_failed(data: str):
print(Fore.LIGHTRED_EX+data+Fore.RESET)

@staticmethod
def print(data):
pprint.pprint(data)
from rich import print
from rich.console import Console
from rich.progress import Progress

console = Console()
progress = Progress()

class Pattern:
@staticmethod
Expand Down
14 changes: 7 additions & 7 deletions yarb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from concurrent.futures import ThreadPoolExecutor, as_completed

from bot import *
from utils import Color, Pattern
from utils import *

import requests
requests.packages.urllib3.disable_warnings()
Expand Down Expand Up @@ -100,9 +100,9 @@ def filter(title: str):
item = {entry.title: entry.link}
print(item)
result |= item
Color.print_success(f'[+] {title}\t{url}\t{len(result.values())}/{len(r.entries)}')
console.print(f'[+] {title}\t{url}\t{len(result.values())}/{len(r.entries)}', style='bold green')
except Exception as e:
Color.print_failed(f'[-] failed: {url}')
console.print(f'[-] failed: {url}', style='bold red')
print(e)
return title, result

Expand Down Expand Up @@ -157,10 +157,10 @@ def init_rss(conf: dict, update: bool=False, proxy_url=''):
if not check:
feeds.append(url)
except Exception as e:
Color.print_failed(f'[-] 解析失败:{value}')
console.print(f'[-] 解析失败:{value}', style='bold red')
print(e)

Color.print_focus(f'[+] {len(feeds)} feeds')
console.print(f'[+] {len(feeds)} feeds', style='bold yellow')
return feeds


Expand Down Expand Up @@ -200,12 +200,12 @@ def job(args):
if result:
numb += len(result.values())
results.append({title: result})
Color.print_focus(f'[+] {len(results)} feeds, {numb} articles')
console.print(f'[+] {len(results)} feeds, {numb} articles', style='bold yellow')

# temp_path = root_path.joinpath('temp_data.json')
# with open(temp_path, 'w+') as f:
# f.write(json.dumps(results, indent=4, ensure_ascii=False))
# Color.print_focus(f'[+] temp data: {temp_path}')
# console.print(f'[+] temp data: {temp_path}', style='bold yellow')

# 更新today
update_today(results)
Expand Down

0 comments on commit bced218

Please sign in to comment.