for headline in news_headlines: print(headline['text'] + '\n' + headline['time_stamp']) headline_exist = NewsHeadline.objects.filter(text=headline['text']) if(len(headline_exist) == 0): headline_entry = NewsHeadline() headline_entry.text = headline['text'] headline_entry.time_stamp = headline['time_stamp'] headline_entry.save() d.csvNewsFileName = '.\\crawler\\news\\news_' + str(datetime.datetime.now().day) +'_' + str(datetime.datetime.now().month) +'_' + str(datetime.datetime.now().year) +'_' + str(datetime.datetime.now().hour) +'_' + str(datetime.datetime.now().minute) + '_' + str(datetime.datetime.now().second) +'.csv' d.DumpNewsCSV(news_headlines) prices = d.ParsePricesURL(priceStartDate) for price in prices: print(price['value'] + '\n' + price['time_stamp']) price_exist = Price.objects.filter(time_stamp=price['time_stamp']) if(len(price_exist) == 0): price_entry = Price() price_entry.value = price['value'] price_entry.time_stamp = price['time_stamp'] price_entry.save() d.csvPricesFileName = '.\\crawler\\prices\\prices_'+ str(datetime.datetime.now().day) +'_' + str(datetime.datetime.now().month) +'_' + str(datetime.datetime.now().year) +'_' + str(datetime.datetime.now().hour) +'_' + str(datetime.datetime.now().minute) + '_' + str(datetime.datetime.now().second) +'.csv' d.DumpPricesCSV(prices) # Crawl every hour time.sleep(3600)
def setUp(self): self.assertTrue(settings.FAKE_SMS_SERVER) # 创建老师 teacher_user = User.objects.create(username=self.teacher_name) teacher_user.password = make_password(self.teacher_password, self.teacher_salt) teacher_user.email = self.teacher_email teacher_user.save() profile = Profile(user=teacher_user, phone=self.teacher_phone) profile.save() teacher = Teacher(user=teacher_user) teacher.save() teacher_group = Group.objects.get(name="老师") teacher_user.groups.add(teacher_group) teacher_user.save() profile.save() teacher.save() teacher_account = Account(user=teacher_user) teacher_account.save() # 为老师创建能力 grade = Grade.objects.get(name="高三") subject = Subject.objects.get(name="英语") ability = Ability.objects.get(grade=grade, subject=subject) teacher.abilities.add(ability) # 设置面试记录 teacher.status = Teacher.INTERVIEW_OK teacher.status_confirm = True # 设置性别 profile.gender = "f" profile.save() # 设置区域 other_region = Region.objects.get(name="其他") teacher.region = other_region # 设置老师级别 teacher_level = Level.objects.all()[0] teacher.level = teacher_level # 为老师创建对应价格 price = Price(region=other_region, ability=ability, level=teacher_level, price=1, salary=2, commission_percentage=3) price.save() # 设置老师名称 teacher.name = self.teacher_name teacher.save() # 创建家长 parent_user = User.objects.create(username=self.parent_name) parent_user.password = make_password(self.parent_password, self.parent_salt) parent_user.email = self.parent_email parent_user.save() parent_profile = Profile(user=parent_user, phone=self.parent_phone) parent_profile.save() parent_group = Group.objects.get(name="家长") parent_user.groups.add(parent_group) parent_user.save() parent_profile.save() parent = Parent(user=parent_user) parent.save() # 创建订单 school = School(name="逗比中学", address="逗比路", region=Region.objects.get(name="其他"), center=True, longitude=0, latitude=0, opened=False) school.save() school.init_prices() # 为老师添加学校 teacher.schools.add(school) order = Order(parent=parent, teacher=teacher, school=school, grade=Grade.objects.get(name="一年级"), subject=Subject.objects.get(name="数学"), coupon=None, price=200, hours=50, total=100, paid_at=make_aware(datetime.datetime.now()), status=Order.PAID) order.save() # 创建订单里的课程 one_time_slot = TimeSlot( order=order, start=make_aware(datetime.datetime(2016, 1, 1, 8, 0, 0)), end=make_aware(datetime.datetime(2016, 1, 1, 10, 0, 0))) one_time_slot.save() one_time_slot = TimeSlot( order=order, start=make_aware(datetime.datetime(2015, 12, 30, 15, 0, 0)), end=make_aware(datetime.datetime(2015, 12, 30, 17, 0, 0))) one_time_slot.save() one_time_slot = TimeSlot( order=order, start=make_aware(datetime.datetime(2015, 12, 20, 11, 0, 0)), end=make_aware(datetime.datetime(2015, 12, 20, 12, 0, 0))) one_time_slot.save() # 检查订单的数目是否正确 order = Order.objects.get(teacher=teacher) self.assertEqual(3, len(order.timeslot_set.filter(deleted=False)))