代码格式化
This commit is contained in:
25
dingtalk.py
25
dingtalk.py
@@ -6,6 +6,7 @@ import base64
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
class DingTalkBot:
|
class DingTalkBot:
|
||||||
"""
|
"""
|
||||||
钉钉机器人类,通过webhook和可选的加签token向群聊发送消息提醒
|
钉钉机器人类,通过webhook和可选的加签token向群聊发送消息提醒
|
||||||
@@ -26,15 +27,16 @@ class DingTalkBot:
|
|||||||
if not self.secret:
|
if not self.secret:
|
||||||
return self.webhook
|
return self.webhook
|
||||||
timestamp = str(round(time.time() * 1000))
|
timestamp = str(round(time.time() * 1000))
|
||||||
secret_enc = self.secret.encode('utf-8')
|
secret_enc = self.secret.encode("utf-8")
|
||||||
string_to_sign = f"{timestamp}\n{self.secret}"
|
string_to_sign = f"{timestamp}\n{self.secret}"
|
||||||
string_to_sign_enc = string_to_sign.encode('utf-8')
|
string_to_sign_enc = string_to_sign.encode("utf-8")
|
||||||
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
|
hmac_code = hmac.new(
|
||||||
|
secret_enc, string_to_sign_enc, digestmod=hashlib.sha256
|
||||||
|
).digest()
|
||||||
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
|
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
|
||||||
url = f"{self.webhook}×tamp={timestamp}&sign={sign}"
|
url = f"{self.webhook}×tamp={timestamp}&sign={sign}"
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
def send_text(self, content: str, at_mobiles=None, is_at_all=False):
|
def send_text(self, content: str, at_mobiles=None, is_at_all=False):
|
||||||
"""
|
"""
|
||||||
发送文本消息
|
发送文本消息
|
||||||
@@ -47,10 +49,7 @@ class DingTalkBot:
|
|||||||
data = {
|
data = {
|
||||||
"msgtype": "text",
|
"msgtype": "text",
|
||||||
"text": {"content": content},
|
"text": {"content": content},
|
||||||
"at": {
|
"at": {"atMobiles": at_mobiles, "isAtAll": is_at_all},
|
||||||
"atMobiles": at_mobiles,
|
|
||||||
"isAtAll": is_at_all
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
url = self._gen_signed_url() if self.secret else self.webhook
|
url = self._gen_signed_url() if self.secret else self.webhook
|
||||||
@@ -78,14 +77,8 @@ class DingTalkBot:
|
|||||||
at_mobiles = at_mobiles or []
|
at_mobiles = at_mobiles or []
|
||||||
data = {
|
data = {
|
||||||
"msgtype": "markdown",
|
"msgtype": "markdown",
|
||||||
"markdown": {
|
"markdown": {"title": title, "text": text},
|
||||||
"title": title,
|
"at": {"atMobiles": at_mobiles, "isAtAll": is_at_all},
|
||||||
"text": text
|
|
||||||
},
|
|
||||||
"at": {
|
|
||||||
"atMobiles": at_mobiles,
|
|
||||||
"isAtAll": is_at_all
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
url = self._gen_signed_url() if self.secret else self.webhook
|
url = self._gen_signed_url() if self.secret else self.webhook
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
import akshare as ak
|
import akshare as ak
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
for symbol in ['NVDA', 'AAPL', 'MSFT', 'AMZN', 'TSLA', 'META', 'GOOGL']:
|
|
||||||
|
for symbol in ["NVDA", "AAPL", "MSFT", "AMZN", "TSLA", "META", "GOOGL"]:
|
||||||
stock_us_daily_df = ak.stock_us_daily(symbol=symbol, adjust="qfq")
|
stock_us_daily_df = ak.stock_us_daily(symbol=symbol, adjust="qfq")
|
||||||
stock_us_daily_df.to_csv(f"{symbol}_stock_us_daily.csv", index=False, encoding="utf-8-sig")
|
stock_us_daily_df.to_csv(
|
||||||
|
f"{symbol}_stock_us_daily.csv", index=False, encoding="utf-8-sig"
|
||||||
|
)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import traceback
|
|||||||
from dingtalk import DingTalkBot
|
from dingtalk import DingTalkBot
|
||||||
import talib as ta
|
import talib as ta
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
env = "online"
|
env = "online"
|
||||||
# env = "on"
|
# env = "on"
|
||||||
db_config = DatabaseConfig(env=env)
|
db_config = DatabaseConfig(env=env)
|
||||||
@@ -104,7 +105,9 @@ def main():
|
|||||||
# dingtalk.send_markdown(
|
# dingtalk.send_markdown(
|
||||||
# f"CCI信号", signal_df.to_markdown(tablefmt="simple", index=False)
|
# f"CCI信号", signal_df.to_markdown(tablefmt="simple", index=False)
|
||||||
# )
|
# )
|
||||||
dingtalk.send_text(tabulate(signal_df, tablefmt='plain', headers="keys", showindex=False))
|
dingtalk.send_text(
|
||||||
|
tabulate(signal_df, tablefmt="plain", headers="keys", showindex=False)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ def get_latest_index_kline_date():
|
|||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
webhook = "https://oapi.dingtalk.com/robot/send?access_token=fb70c1561d8beba94b4f11568f4bb15e3ae07ccbdc8ac19676434a9d1cd17546" # 填写你的webhook
|
webhook = "https://oapi.dingtalk.com/robot/send?access_token=fb70c1561d8beba94b4f11568f4bb15e3ae07ccbdc8ac19676434a9d1cd17546" # 填写你的webhook
|
||||||
secret = "SEC1ae7cd2f1a6f9da3611af37da3e7d954c1e8533fc073c6c8cc5e5af3b6e5926b" # 填写你的加签token(如果有),否则留空
|
secret = "SEC1ae7cd2f1a6f9da3611af37da3e7d954c1e8533fc073c6c8cc5e5af3b6e5926b" # 填写你的加签token(如果有),否则留空
|
||||||
@@ -102,4 +100,3 @@ if __name__ == "__main__":
|
|||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user