def test_print_post(self): post = Post('Post Title', 'Post Content') expected_print = '''---- Post Title ---- Post Content''' with patch('builtins.print') as mocked_print: app.print_post(post) mocked_print.assert_called_with(expected_print)
def get_add_data(post_data): """ Geolocates the post, finds the user's other image posts and gets the closest wikipedia artile """ post = None user = None geo = None loc_info = None add_data = None try: created = post_data['created'] except KeyError: created = post_data['created_utc'] post = Post(post_data['id'], created, post_data['url'], post_data['author'], post_data['title'], post_data['score'], post_data['num_comments']) user = UserContent(post.author) geo = Geolocation(post.token_title()) loc_info = LocationInfo(geo.lat, geo.lng) add_data = { 'token_title': post.token_title(), 'updated_score': post.updated_score(), 'thumb_url': post.thumb_url(), 'other_posts': user.other_posts(), 'pie_chart': user.pie_chart(), 'opencage_geo': geo.geocode_array, 'loc': geo.location(), 'geoJSON': loc_info.geoJSON(post), 'wiki_page_id': loc_info.wiki_page_ids_all(), 'wiki_content': loc_info.closest_wiki_content(), 'wiki_title': loc_info.closest_wiki_title(), 'wiki_extract': loc_info.closest_wiki_extract() } return add_data
def find_at(self, lat, long): ret = [] loca = Location(lat, long, 0, int(time.time())) model = Post(0, loca, '', '', '') for post in self.data.values(): if (self.equal_enough(model, post)): ret.append(post) return ret
def new_post(self): print("Creating a new post") title = input("Enter post title: ") content = input("Enter post content: ") date = input("Enter date in format DDMMYYY :") print("Calling Post class with collected inputs.") post = Post(blog_id=self.id, title=title, content=content, author=self.author, date=datetime.datetime.strptime(date, "%d%m%Y")) post.save_to_mongo()
def execute(): # TODO update this config = Config() try: title = sys.argv[1] file_name = sys.argv[2] except IndexError: functions.exit() return wp = Client(config.data[config.url], config.data[config.user], config.data[config.pwd]) # Create a Post post = Post(wp, title, file_name) manager = ManagePost(post) manager.sendPost()
def submit_post(): cookies_id = request.cookies.get('auth_id') title = request.json['title'] author = request.json['author'] story = request.json['story'] passphrase = request.json['passphrase'] searchable = request.json['searchable'] post = Post(author, title, story, cookies_id, searchable, passphrase) db.session.add(post) db.session.commit() id = post.id response_data = { 'linkText': id } return jsonify(response_data)
def new_post(): #saves new post to db print request post_dict = request.json #post_dict = dejsonify_posts(post_json) #id,location,body,owner_disp,owner_id lat = post_dict['location']['latitude'] long = post_dict['location']['longitude'] alt = post_dict['location']['altitude'] timestamp = post_dict['location']['timestamp'] post = Post(database.gen_id(), \ Location(lat,long,alt,timestamp), \ post_dict['postContent'], \ post_dict['dispName'], \ post_dict['userID']) database.add(post.id,post) return 'added!'
def post(self): subject = self.request.get("subject") content = self.request.get("content") author = self.user.username active_user = self.read_user() if active_user: if subject and content: new_post = Post(parent=blog_key(), subject=subject, author=author, content=content, likes=0, liked_by=[]) new_post.put() self.redirect("/blog/%s/" % str(new_post.key().id())) else: error = "Subject and content, please!" self.render_post(error=error) else: self.redirect("/login")
active_user = ANS1[ans]() ans = None if active_user.role == 'user': ANS2 = ['1', '2'] while ans not in ANS2 and ans != '2': print(f'possible actions:') ans = input('1. Add post \n2. Sign out\nplease choose :') if ans == '1': title = input('type your post title: ') text = input('type your post: ') Post(active_user, title, text) ans = None elif ans == '2': active_user = None break elif active_user.role == 'admin': ANS2 = ['1', '2', '3'] while ans not in ANS2 and ans != '3': print(f'possible actions:') ans = input('1. See user list \n2. See last 3 posts\n3. Sign out\nplease choose :') if ans == '1': for el in User.population.keys():
def test_create_post(self): p = Post('Test','Tests Content') self.assertEqual('Test',p.title) self.assertEqual('Tests Content',p.content)
def test_json(self): p = Post('Test','Tests Content') expected = {'title':'Test', 'content': 'Tests Content'} self.assertDictEqual(expected, p.json())
def setUp(self): self._today = datetime.datetime.today() self.p = Post(self._today, "https://", "Bla-bla-bla") print("\n<--- TestExpImpFile: %s" % self._today.strftime(DATETIME_FORMAT))
def startscan(self): database = Database() print("[INFO] starting video stream...") vs = VideoStream(src=0).start() #vs = VideoStream(usePiCamera=True).start() time.sleep(2.0) found = set() unfound = set() empty = set() # loop over the frames from the video stream while True: # grab the frame from the threaded video stream and resize it to # have a maximum width of 400 pixels frame = vs.read() frame = imutils.resize(frame, width=400) # find the barcodes in the frame and decode each of the barcodes barcodes = pyzbar.decode(frame) # loop over the detected barcodes for barcode in barcodes: # extract the bounding box location of the barcode and draw # the bounding box surrounding the barcode on the image (x, y, w, h) = barcode.rect cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2) # the barcode data is a bytes object so if we want to draw it # on our output image we need to convert it to a string first barcodeData = barcode.data.decode("utf-8") barcodeType = barcode.type # draw the barcode data and barcode type on the image text = "{} ({})".format(barcodeData, barcodeType) cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) upc = str((barcode[0])) upc = upc.strip("a,b,'") print(upc) item = None if len(database.checkforitem(upc)) is 0: #politely check for data before sending api request p = Pull() item = p.pullitem(upc) print(item) if item is None and len(database.checkforitem(upc)) is 0: #item does not exist in either print("Detected unknown item...") time.sleep(0.2) a = input("What is the name of the object with barcode: {}: ".format(str(upc))) database.insert(a,upc) dopost = input("Would you like to send this to the api for future reference? y/n: ") if dopost is "y": post = Post() post.postitem(a,upc) time.sleep(2) #prevents multiple entries of the same item elif item is None and len(database.checkforitem(upc)) is not 0: #item already found, increasing quantity instead print("Item found in local database, increasing quantity by one.") database.selectbyupc(upc) time.sleep(1.5) elif item != None: #api request successful print("Found upc code {}, inserting into known database.".format(str(upc))) database.insert(str(item),upc) time.sleep(2) # show the output frame cv2.imshow("Barcode Scanner", frame) key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q"): break print("[INFO] cleaning up...") cv2.destroyAllWindows() vs.stop()
def create_post(self, title, content): self.posts.append(Post(title, content))
def setUp(self): self.locationinfo = LocationInfo(51.5032803, -0.1196873) self.post = Post('8405kv', '946684800', 'https://www.imgur.xyz/home/pic.jpg', 'will', 'This is a picture of Sheffield', 5555, 33)
def setUp(self): self.post = Post('8405kv', '946684800', 'https://www.imgur.xyz/home/pic.jpg', 'will', 'This is a picture of Sheffield', 5555, 33)