def receive_message(): try: if request.method == 'GET': """Before allowing people to message your bot, Facebook has implemented a verify token that confirms all requests that your bot receives came from Facebook.""" token_sent = request.args.get("hub.verify_token") return verify_fb_token(token_sent) else: output = request.get_json() for event in output['entry']: messaging = event['messaging'] for message in messaging: if message.get('message'): recipient_id = message['sender']['id'] if message['message'].get('text'): msg = message['message'].get('text') rollbar.report_message( "message received[{}]: {}".format( recipient_id, msg), "info") opt = Options(MongoCrud(), Chart()) fb_responses = opt.answer_message( recipient_id, msg) for response_sent_text in fb_responses: send_message(opt, recipient_id, response_sent_text) return "Message Processed" except: rollbar.report_exc_info()
def test_new_value(self): fb_id = 1234 request = "50.5" opt = Options(MongoCrud()) response = opt.answer_message(fb_id, request) expected = "OK, you are {} kg today".format(request) self.assertEquals(response[0], expected)
def test_stat(self): fb_id = 1234 request = "Stat" opt = Options(MongoCrud()) response = opt.answer_message(fb_id, request) expected = "your planned weigth for today is: 0 kg" self.assertEquals(response[0], expected)
def test_register(self): fb_id = 1234 request = "Register 100 2018-06-01 90" opt = Options(MongoCrud()) response = opt.answer_message(fb_id, request) expected = "Your plan has been registered" self.assertEquals(response[0], expected)
def test_random_msg(self): fb_id = 1234 request = "?" opt = Options(MongoCrud()) response = opt.answer_message(fb_id, request) expected = "version:" first_line = response[0].split("\n")[1].strip()[:len(expected)] self.assertEquals(first_line, expected)
DISPLAY = 'DISPLAY' in os.environ if not DISPLAY: matplotlib.use('Agg') import matplotlib.pyplot as plt from tools.options import Options from network.atloc import AtLoc, AtLocPlus from torchvision import transforms, models from tools.utils import quaternion_angular_error, qexp, load_state_dict from data.dataloaders import SevenScenes, RobotCar, MF, Topo, Topo2, Topo3 from torch.utils.data import DataLoader from torch.autograd import Variable import math # Config opt = Options().parse() cuda = torch.cuda.is_available() device = "cuda:" + ",".join(str(i) for i in opt.gpus) if cuda else "cpu" # Model feature_extractor = models.resnet34(pretrained=False) atloc = AtLoc(feature_extractor, droprate=opt.test_dropout, pretrained=False, lstm=opt.lstm) if opt.model == 'AtLoc': model = atloc elif opt.model == 'AtLocPlus': model = AtLocPlus(atlocplus=atloc) else: raise NotImplementedError
#!/usr/bin/python # -*- coding: utf-8 -*- import os import sys from file_manager.vhdl_reader import Vhdl_reader from decorator.pdfdrawer import PdfDrawer from tools.options import Options """ pyVhdl2Sch takes a .vhd file and return a pdf : name_of_the_entity.pdf. """ options = Options() files = [] options.analyse_args(sys.argv) for i in range(0, len(options.files)): filename = options.files[i] try: os.path.isfile(filename) except: print("File do not exist!\n") options.print_usage() sys.exit reader = Vhdl_reader(filename, options) options.filename = "%s." % reader.entity.name + "%s" % options.format drawer = PdfDrawer("%s." % reader.entity.name + "%s" %
def init_vars(self): self.Vhdl_Code = "" self.options = Options()
DISPLAY = 'DISPLAY' in os.environ if not DISPLAY: matplotlib.use('Agg') # 设置后端,Matplotlib绘图并保存图像但不显示图形 import matplotlib.pyplot as plt from tools.options import Options from network.atloc import AtLoc from torchvision import transforms, models from tools.utils import quaternion_angular_error, qexp, load_state_dict from torch.utils.data import DataLoader from data.dataloaders import SevenScenes, RobotCar from torch.autograd import Variable # 配置运行环境 opt = Options().parse() # 参数命令解析 cuda = torch.cuda.is_available() # 判断是否有可用gpu设备 device = "cuda" + ",".join( str(i) for i in opt.gpus) if cuda else "cpu" # 获取gpu或cpu设备信息 # 模型设置 feature_extractor = models.resnet34(pretrained=False) # resnet34模型作为特征提取器 atloc = AtLoc(feature_extractor, droprate=opt.test_dropout, pretrained=False) # atloc模型实例构建 if opt.model == 'AtLoc': model = atloc else: raise NotImplementedError # model.eval(),pytorch会自动把BN和DropOut固定住,不会取平均,而是用训练好的值 # 不然的话,一旦test的batch_size过小,很容易就会被BN层导致生成图片颜色失真极大