def handle_bar(context, bar_dict): # 开始编写你的主要的算法逻辑 # bar_dict[order_book_id] 可以拿到某个证券的bar信息 # context.portfolio 可以拿到现在的投资组合状态信息 # 使用order_shares(id_or_ins, amount)方法进行落单 # TODO: 开始编写你的算法吧! esp = context.esp code = context.code stock = bar_dict[code] stock.code = code close = stock.close datetime = stock.datetime name = stock.symbol today = datetime.strftime('%Y-%m-%d') mpe = close / esp if mpe < 30: order_percent(code, 1) if (context.today == today and context.projectName == 'one_strategy'): print(code + '_' + name + '********************买入') from mail.mail import send_mail send_mail(stock, 'buy') if mpe > 50: order_percent(code, -1) if (context.today == today and context.projectName == 'one_strategy'): print(code + '_' + name + '********************卖出') from mail.mail import send_mail send_mail(stock, 'sell')
def send_packet(self, smtp_connection, packet): text = '' text += 'UserAgent: ' + self.agent_edition + ' (' + self.os_info + ')\r\n' text += 'Sequence: ' + str(packet.sequence) + '\r\n' text += 'Keyid: ' + packet.signed_keyid + '\r\n' text += '\r\n' + packet.message return mail_agent.send_mail(smtp_connection, packet.sender, packet.receiver, text, packet.uuid)
def run(self): while True: try: (receiver, contents, attachments) = self.queue.get(timeout=1) except queue.Empty: if self.queue.is_stopped(): logger.info("postman job finish stop!") break else: result = send_mail(receiver, contents, attachments) if result != True: logger.error("postman send mail to " + str(receiver) + "fail") sleep(self.sleeping_time)
def send_user_check_email(email): """Send first check email to user. Args: email : str Returns: success: bool """ receiver = [email] body_text = ("您好,我是折光观察者,服务于公众号「时间从来不回答」\n" "收到这封邮件是因为您在公众号内初次绑定了邮箱\n" "我向您发送邮件以确认您此后能正确收到邮件通知\n" "若本邮件被误分类为垃圾邮件,建议点击「这不是垃圾邮件」帮我逃离\n" "另外,建议将本邮箱添加至通讯录/联系人列表,避免此后通知邮件再被误分类\n" "\n\n\n如果您不知道为何收到本邮件,请联系:[email protected] 处理") msg = {'Subject': '初次绑定邮箱通知', 'Body': body_text} return send_mail(receiver, contents=msg)
def notify_user(email, URL, backup_addr): """Send email to users. Send email to users for notifying article expiration. With backup file attached. Args: URL : str backup_addr : str Returns: success: bool """ receiver = [email] if backup_addr == None: addition = '\n截止观察结束时,没有成功备份的文档存留。\n如有疑问请联系管理员:[email protected]' attach = [] else: addition = '\n附件是文章备份,请查收。' attach = [backup_addr] body_text = '您观察的文章:' + URL + ' 已失效/超出观察期。' + addition msg = {'Subject': '您的观察目标有状态更新', 'Body': body_text} return send_mail(receiver, contents=msg, attachments=attach)
parser.add_option("--mail", action="store", dest="send_mail", help='gmail address') parser.add_option("--mpwd", action="store", dest="mail_password", help='mail password') parser.add_option("--num", action="store", dest="booking_num", type = "int",help='booking numbers') parser.add_option("--mon", action="store", dest="months", help='booking months') (options, args) = parser.parse_args() if not options.username or \ not options.password or \ not options.send_mail or \ not options.mail_password or \ not options.booking_num or \ not options.months: parser.print_usage() exit() new_book = auto_book(options) new_book.slot_set(options) while 1: try: new_book.search_book(options) result = new_book.Check_result(options) if result != 'no book': time.sleep(2) mail.send_mail(send_mail,mail_password,send_to,'new booking',result) new_book.slot_set(options) else: time.sleep(2) except KeyboardInterrupt: exit()
def trigger(): ''' aggregation of all modules here''' #1. get data input_data = get_input_data() #2 Extract news and process news into dictionary news_map = get_news() #2 XLS generate generate_xlx_report(input_data) #4 subscription_data = get_subs_data() #5, get user --> interested states user_state_info = generate_user_report(subscription_data, input_data) print("--------Mail content-------") print(news_map) print(user_state_info) #format mail, just for readability TAB = '\t' NEWLINE = '\n' print("Processing data collected from NEWS module..") processed_news_text = '\n----- HEADLINES -----\n' for link, headline in news_map.items(): #import pdb;pdb.set_trace() insert_row( 'news', (datetime.date.today().strftime('%Y-%m-%d'), link, headline)) processed_news_text = processed_news_text + headline + TAB + link + NEWLINE print(processed_news_text) get_rows('news', '2020-08-26') draw_graph() #6. Send mail with above data. # 1. user specific data. # 2. XLS, attachment # 3. News. dashline = "----------------------------------" XLS_REPORT_FILENAME = 'statewise_covid_report.xls' for user, content in user_state_info.items( ): #contenet is statename and numver mail_text = "Subscribed states:\n" + dashline + NEWLINE for state_data in content: for state, active_cases in state_data.items(): mail_text = state + " : " + str(active_cases) + "\n" mail_text = mail_text + "\n" + dashline + "\n" + processed_news_text SIGNATURE = "\n\nRegards,\n Automated Mailservice" mail_text = mail_text + SIGNATURE + "\n" subject_line = "Python mini-project: COVID: Dashboard" print("Sending mail to: ", user) #, "with:", mail_text) send_mail(user, subject_line, mail_text, attachment=XLS_REPORT_FILENAME)
self.user = user self.date = Date(user.timezone) self.weather = WeatherToday(user.location) self.news = NewsToday() self.languages = [Language(language) for language in user.languages] # THIS SQL STUFF IS UGLY AND IS JUST TEMPORARY UNTIL I SCALE UP TO DJANGO. def dict_factory(cursor, row): """Function to turn sqllite query into dict.""" d = {} for idx, col in enumerate(cursor.description): d[col[0]] = row[idx] return d conn = sqlite3.connect(dir_path + '/main.db') conn.row_factory = dict_factory c = conn.cursor() users = c.execute('''SELECT * FROM users''').fetchall() for user in users: print('Preparing Briefing for {}'.format(user['first'])) data = { 'subject': "Your Daily Briefing, {}".format(datetime.now().strftime("%A, %d %B")), 'briefing': Briefing(User(user)) } send_mail(data)