def setUp(self): query_user = User.query.filter_by(email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Readability' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user with open('Readability.json') as json_file: create_file = open(os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_readability.json'), 'w+') self.data = json_file.read() self.json_data = json.loads(self.data)['bookmarks'] self.bookmarks = {} for bmark in self.json_data: url = bmark['article__url'] self.bookmarks[url] = bmark create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = ReadabilityParser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all() self.html_parser = HTMLParser()
def setUp(self): query_user = User.query.filter_by(email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Netscape' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user self.html_parser = HTMLParser() with open('Netscape.html') as json_file: create_file = open( os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_netscape.html'), 'w+') self.data = json_file.read() self.html_data = BeautifulSoup3(self.data) self.bookmarks = {} urls = self.html_data.findAll('a') for link in urls: url = link['href'] if url in self.bookmarks: pass else: tags = ['Imported'] if link.has_key('add_date'): added_timestamp = int(link['add_date']) else: added_timestamp = time.time() self.bookmarks[url] = { 'href': self.html_parser.unescape(url), 'title': self.html_parser.unescape(link.text), 'tags': tags, 'added_on': datetime.datetime.utcfromtimestamp(added_timestamp) } create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = Parser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all()
def setUp(self): query_user = User.query.filter_by(email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Netscape' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user self.html_parser = HTMLParser() with open('Netscape.html') as json_file: create_file = open(os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_netscape.html'), 'w+') self.data = json_file.read() self.html_data = BeautifulSoup3(self.data) self.bookmarks = {} urls = self.html_data.findAll('a') for link in urls: url = link['href'] if url in self.bookmarks: pass else: tags = ['Imported'] if link.has_key('add_date'): added_timestamp = int(link['add_date']) else: added_timestamp = time.time() self.bookmarks[url] = { 'href': self.html_parser.unescape(url), 'title': self.html_parser.unescape(link.text), 'tags': tags, 'added_on': datetime.datetime.utcfromtimestamp( added_timestamp) } create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = Parser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all()
def setUp(self): query_user = User.query.filter_by( email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Instapaper' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user with open('Instapaper.html') as json_file: create_file = open( os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_instapaper.html'), 'w+') self.data = html.document_fromstring(json_file.read()) self.data = html.tostring(self.data) self.html_data = BeautifulSoup4(self.data) self.bookmarks = {} for tag in self.html_data.find_all('h1'): parent_elem = tag.find_next_sibling('ol') links = parent_elem.find_all('a') for link in links: title = link.text url = link['href'] tags = [tag.text] tags.append('Imported') # Thanks Instapaper for not adding timestamps self.bookmarks[url] = { 'href': url, 'title': title, 'tags': tags } create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = InstapaperParser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all() self.html_parser = HTMLParser()
def setUp(self): query_user = User.query.filter_by(email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Instapaper' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user with open('Instapaper.html') as json_file: create_file = open(os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_instapaper.html'), 'w+') self.data = html.document_fromstring(json_file.read()) self.data = html.tostring(self.data) self.html_data = BeautifulSoup4(self.data) self.bookmarks = {} for tag in self.html_data.find_all('h1'): parent_elem = tag.find_next_sibling('ol') links = parent_elem.find_all('a') for link in links: title = link.text url = link['href'] tags = [tag.text] tags.append('Imported') # Thanks Instapaper for not adding timestamps self.bookmarks[url] = { 'href': url, 'title': title, 'tags': tags } create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = InstapaperParser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all() self.html_parser = HTMLParser()
def setUp(self): query_user = User.query.filter_by(email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Pocket' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user with open('Pocket.html') as json_file: create_file = open( os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_pocket.html'), 'w+') self.data = json_file.read() self.html_data = BeautifulSoup4(self.data) self.bookmarks = {} for link in self.html_data.find_all('a'): tags = link['tags'].split(',') tags.append('Imported') dt = datetime.datetime.utcfromtimestamp( float(link['time_added'])) self.bookmarks[link['href']] = { 'href': link['href'], 'title': link.text, 'tags': tags, 'dt': dt } create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = PocketParser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all() self.html_parser = HTMLParser()
def setUp(self): query_user = User.query.filter_by(email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Pocket' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user with open('Pocket.html') as json_file: create_file = open(os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_pocket.html'), 'w+') self.data = json_file.read() self.html_data = BeautifulSoup4(self.data) self.bookmarks = {} for link in self.html_data.find_all('a'): tags = link['tags'].split(',') tags.append('Imported') dt = datetime.datetime.utcfromtimestamp(float(link['time_added'])) self.bookmarks[link['href']] = { 'href': link['href'], 'title': link.text, 'tags': tags, 'dt': dt } create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = PocketParser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all() self.html_parser = HTMLParser()
def setUp(self): query_user = User.query.filter_by( email='*****@*****.**').first() if query_user: query_bookmarks = Bookmark.query.filter_by(user=query_user.id) for bmark in query_bookmarks: db.session.delete(bmark) db.session.commit() db.session.delete(query_user) db.session.commit() create_user = User() create_user.first_name = 'Readability' create_user.last_name = 'Test' create_user.email = '*****@*****.**' create_user.password = '******' create_user.active = True create_user.confirmed_at = datetime.datetime.utcnow() db.session.add(create_user) db.session.commit() self.user = create_user with open('Readability.json') as json_file: create_file = open( os.path.join(app.config['CRESTIFY_UPLOAD_DIRECTORY'], 'test_readability.json'), 'w+') self.data = json_file.read() self.json_data = json.loads(self.data)['bookmarks'] self.bookmarks = {} for bmark in self.json_data: url = bmark['article__url'] self.bookmarks[url] = bmark create_file.write(self.data) self.file_path = create_file.name create_file.close() init_parser = ReadabilityParser(self.file_path, self.user.id) init_parser.process() init_parser.add_to_database() self.query = Bookmark.query.filter_by(user=self.user.id).all() self.html_parser = HTMLParser()