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 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(self): query = Post.query() all_posts = query.fetch() template_vars = { "all_posts": all_posts, } template = the_jinja_env.get_template('templates/all_posts.html') self.response.write(template.render(template_vars))
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 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 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")
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 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 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 render_front(self): posts = Post.all().order("-date") self.render("blog.html", posts=posts)
def showpost(name): post = Post.find_post(name) html = post.load_content() return 'Post name: ' + post.name + " content: " + html
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 __init__(self, args=None): super(PostController, self).__init__() self._post = Post()
def __init__(self): self._post = Post()
def setUp(self): 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.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)
class PostTest(unittest.TestCase): def setUp(self): self.post = Post('8405kv', '946684800', 'https://www.imgur.xyz/home/pic.jpg', 'will', 'This is a picture of Sheffield', 5555, 33) def test_token_title_default(self): """ Test that lower case words are not tokenized """ self.assertEqual(self.post.token_title(), ["Sheffield"]) def test_token_title_lower(self): """ Test that lower case words are not tokenized """ self.post.title = "london sheffield exeter leeds" self.assertEqual(self.post.token_title(), []) def test_token_title_upper(self): """ Test that upper case words are tokenized """ self.post.title = "London Sheffield Exeter Leeds" self.assertEqual(self.post.token_title(), ["London", "Sheffield", "Exeter", "Leeds"]) def test_token_title_upper_stop_words(self): """ Test that stop words are not tokenized """ self.post.title = "This Is A String" self.assertEqual(self.post.token_title(), ["String"]) def test_token_title_oc(self): """ Test that OC is not tokenized """ self.post.title = "London Sheffield Exeter Leeds OC" self.assertEqual(self.post.token_title(), ["London", "Sheffield", "Exeter", "Leeds"]) def test_token_title_distance(self): """ Test that Distance not tokenized """ self.post.title = "London Sheffield Exeter Leeds Distance" self.assertEqual(self.post.token_title(), ["London", "Sheffield", "Exeter", "Leeds"]) def test_token_title_lower_punctuation(self): """ Test that punctuation does not affect result """ self.post.title = "£london *sheffield exeter? leeds!" self.assertEqual(self.post.token_title(), []) def test_token_title_upper_punctuation(self): """ Test that punctuation does not affect result """ self.post.title = "£London *Sheffield Exeter? Leeds!" self.assertEqual(self.post.token_title(), ["Exeter", "Leeds"]) def test_token_title_upper_stop_words_punctuation(self): """ Test that punctuation does not affect result """ self.post.title = "This Is A A! String! ?! £$£$ ^^&" self.assertEqual(self.post.token_title(), ["String"]) def test_token_title_numbers(self): """ Test that numbers are not tokenized """ self.post.title = "11 {22} [33] <44> ~55~ [6*7] 9cc 0leeds 10Exeter" self.assertEqual(self.post.token_title(), []) def test_thumb_url_no_image(self): """ Test that url remains the same if imgur not in url """ self.post.url = "https://www.mapforreddit.xyz/home/index.html" self.assertEqual(self.post.thumb_url(), self.post.url) def test_thumb_url_image_jpg(self): """ Test that url remains the same if imgur not in url """ self.post.url = "https://www.mapforreddit.xyz/home/pic.jpg" self.assertEqual(self.post.thumb_url(), self.post.url) def test_thumb_url_image_png(self): """ Test that url remains the same if imgur not in url """ self.post.url = "https://www.mapforreddit.xyz/home/pic.png" self.assertEqual(self.post.thumb_url(), self.post.url) def test_thumb_url_imgur_image_jpg(self): """ Test that thumbnail image is selected if imgur in url """ self.post.url = "https://www.imgur.xyz/home/pic.jpg" self.assertEqual(self.post.thumb_url(), "https://www.imgur.xyz/home/picm.jpg") def test_thumb_url_imgur_image_png(self): """ Test that thumbnail image is selected if imgur in url """ self.post.url = "https://www.imgur.xyz/home/pic.png" self.assertEqual(self.post.thumb_url(), "https://www.imgur.xyz/home/picm.png") def test_thumb_url_imgur_random_ext(self): """ Test that a random extension is not converted """ self.post.url = "https://www.imgur.xyz/home/pic.mp3" self.assertEqual(self.post.thumb_url(), self.post.url) def test_thumb_url_random(self): """ Test that randpm characters are not converted """ self.post.url = "dfg fdgdfg fdg sdfg 3241324134 456 xdbvxcvb" self.assertEqual(self.post.thumb_url(), self.post.url) def test_updated_score_working_id(self): """ Test that a working id works """ self.post.id = "8405kv" self.assertIsInstance(self.post.updated_score(), int) def test_updated_score_broken_id(self): """ Test that a broken id dosent break it """ self.post.id = "dQw4w9WgXcQ" self.assertEqual(self.post.updated_score(), self.post.score)
def create_post(self, title, content): self.posts.append(Post(title, content))
def get_posts(self): print("Get posts from post collections with blogid") return Post.from_blog(self.id)
class PostController(MasterController): _post = None def __init__(self, args=None): super(PostController, self).__init__() self._post = Post() def show(self, args=None): posts = None post_id = None api = False if args: if 'post_id' in args.keys(): post_id = args['post_id'] if 'api' in args.keys(): api = True posts = None content = '' posts = self._post.all() print 'Content-Type: text/html\n' print if api: content = json.dumps(posts) else: content += self.HEADER content += self.markup(posts) content += self.FOOTER print content def create(self, args): # Attach view to be updated self._post.attach(PostController) # set fields self._post.post(args['post']) self._post.user_id(args['user_id']) #_post.lat(args['lat']) #_post.lng(args['lng']) #save post self._post.save() def delete(self, args): self._post.attach(PostController) self._post.destroy(args['post_id'])
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():
class PostController(MasterController): _post = None def __init__(self): self._post = Post() def show(self, args=None): post_id = None api = False if args: if 'post_id' in args.keys(): post_id = args['post_id'] if 'api' in args.keys(): api = True posts = None content = None if post_id: posts = self._post.fetch(post_id) else: posts = self._post.all() if api: posts_dict = dict() while True: post = posts.fetch_row(1,1) if not post: break posts_dict[post[0]['post_id']] = { 'post_id' : post[0]['post_id'], 'user_id' : post[0]['user_id'], 'lat' : str(post[0]['lat']), 'lng' : str(post[0]['lng']), 'post' : post[0]['post'], 'created_at' : str(post[0]['created_at']) } content = json.dumps(posts_dict) else: content = self.markup(posts) print content def create(self, args): # Attach view to be updated self._post.attach(self.show()) # set fields self._post.post(args['post']) #_post.user_id(args['user_id']) #_post.lat(args['lat']) #_post.lng(args['lng']) #save post self._post.save() def edit(self, args): post_id = args['post_id'] def update(self, args): post_id = args['post_id'] post = args['post']