def create_documents(create_blog=True, create_cyoa=True, create_other=True): ignore = lambda x: 0 if create_blog: b = blog.Blog() def process_blog(path): try: b.read_from_file(path) except: print("Failed to read blog file", path) raise else: process_blog = ignore if create_other: docs_other = [] def process_other(path): docs_other.append(document.WebDocument.from_source_path(path)) else: process_other = ignore walk_input(process_blog, process_other) docs_all = [] if create_other: docs_all.extend(docs_other) if create_blog: docs_all.extend(b.create_documents()) if create_cyoa: docs_all.extend(create_cyoa_documents()) return docs_all
def __init__(self, master=None): self.blog_handler = blg.Blog() super().__init__(master) # languages self.languages = ["fi", "en"] self.selected = tk.StringVar() self.language_label = tk.Label(self) self.language_select = tt.Combobox(self, textvariable=self.selected, values=self.languages) self.build_language_field() # date self.date_label = tk.Label(self) self.date_input = tk.Text(self) self.build_date_fields() # description self.description_label = tk.Label(self) self.description_input = tk.Text(self) self.build_description_fields() # series self.series_selected = tk.StringVar() self.series_selected.set(self.blog_handler.get_series()[0]) self.series_label = tk.Label(self) self.series_select = tt.Combobox(self, textvariable=self.series_selected, values=self.blog_handler.get_series()) self.build_series_field() # header img self.headerIMG_label = tk.Label(self) self.headerIMG_input = tk.Text(self) self.build_headerIMG_fields() # title self.title_label = tk.Label(self) self.title_input = tk.Text(self) self.build_title_fields() # view self.view_label = tk.Label(self) self.view_input = tk.Text(self) self.build_view_fields() # save self.save_btn = tk.Button(self) self.build_save_button() # master self.master = master self.pack() self.winfo_toplevel().title( "Cats opinion admin panel - Insert blog post")
def ask_create_blog(): title = input("What is the blog title? ") author = input("Who is the author? ") # save user input in the blogs dic with the key [title]; # if the key doesn't exist yet, it is created automatically blogs[title] = blog.Blog(title, author)
import os import blog as bg blog = bg.Blog() blog.clear() sample_file = os.path.join(os.getcwd(), "name_samples.txt") if not os.path.isfile(sample_file): raise ValueError f = open(sample_file) blog_count = 0 while True: line = f.readline() if not line: break # TO FILL USERS first_name, last_name, password = line.strip().split() username = (first_name + last_name).lower() blog.user_add(username=username, first_name=first_name, last_name=last_name, password=password) if blog_count % 10 == 0: # TO FILL BLOGS sess_id = blog.login(username=username, password=password) blog_title = f"{username}'s blog" blog.blog_create(title=blog_title, description=f"{first_name} {last_name}", sess_id=sess_id)
def close_database(db, dbc): dbc.commit() dbc.close() app = Flask(__name__) dbc = sqlite3.connect('store/db.db', check_same_thread=False) dbc.row_factory = sqlite3.Row db = dbc.cursor() user_handle = user.Logins(db, dbc) blog_inst = blog.Blog(db, dbc, user_handle) forum = forum.ForumHandler(db, dbc, user_handle) @app.route("/forum/section/<sect>") def view_section(sect): if "token" in session: if user_handle.is_token_valid(session["token"]): user_handle.revalidate_token(session["token"]) else: del session["token"] return forum.view_section(sect) @app.route("/forum/get_threads/<path:section>")
def __init__(self, mongodb): control = MongoDB_control.Control(mongodb) self.blog = blog.Blog(control)
def test_blog(self): blog = bg.Blog() blog.clear() self.assertFalse( blog.blog_create('My first blog', 'Technical reviews', sess_id='random')) password = '******' self.assertTrue(blog.user_add('alex', 'Alexander', 'Kolue', password)) password2 = blog.user_add('hannamon12', 'Hanna', 'Monta') sess_id = blog.login('alex', password) sess_id2 = blog.login('hannamon12', password2) self.assertTrue( blog.blog_create('My first blog', 'Technical reviews', sess_id=sess_id)) self.assertTrue( blog.blog_create('My second blog', 'Nat Geo news', sess_id=sess_id)) self.assertTrue( blog.blog_create('My third blog', 'Nat Geo Wild', sess_id=sess_id)) self.assertTrue( blog.blog_edit(title='My first blog', new_title='My new blog', sess_id=sess_id)) self.assertTrue( blog.blog_edit(title='My new blog', new_desc='NASA news', sess_id=sess_id)) self.assertTrue( blog.post_create( title='Hello', text='Hi, all!', blogs=['My first blog', 'My second blog', 'Unreal blog'], sess_id=sess_id)) self.assertEqual(['alex', 'hannamon12'], blog.get_users(sess_id=sess_id)) self.assertTrue( blog.post_edit('Hello', new_title='Hello everyone!', new_text='Hello world!', new_blogs=['My second blog', 'My third blog'], sess_id=sess_id)) self.assertFalse(blog.post_delete('Hello', sess_id=sess_id)) self.assertEqual(['My new blog', 'My second blog', 'My third blog'], blog.get_active_blogs(sess_id=sess_id)) self.assertTrue(blog.blog_delete('My second blog', sess_id=sess_id)) self.assertTrue(blog.post_delete('Hello everyone!', sess_id=sess_id)) self.assertTrue( blog.post_create(title='Hello', text='Hi, all!', blogs=['My new blog', 'My second blog'], sess_id=sess_id)) self.assertTrue( blog.blog_create("Hanna's blog", "Hanna's interviews", sess_id=sess_id2)) self.assertTrue( blog.post_create(title="My first post", text="Hi, all! I'm Hanna", blogs=["Hanna's blog"], sess_id=sess_id2)) self.assertEqual(['My new blog', 'My third blog', "Hanna's blog"], blog.get_active_blogs(sess_id=sess_id2)) self.assertTrue( blog.comment_create(post_title="My first post", post_owner="hannamon12", comment_title="First comment", comment_text="You are done great job!", sess_id=sess_id)) password3 = blog.user_add('johnS', 'John', 'Sours') sess_id3 = blog.login('johnS', password3) self.assertTrue( blog.comment_create(post_title="My first post", post_owner="hannamon12", comment_title="Second comment", comment_text="It's a cool blog, Hanna!", sess_id=sess_id3)) self.assertTrue( blog.comment_create(post_title="My first post", post_owner="hannamon12", to_comment_title="First comment", to_comment_user="******", comment_title="Comment to comment", comment_text="Hello, Alexander!", sess_id=sess_id3)) self.assertTrue( blog.comment_create(post_title="My first post", post_owner="hannamon12", comment_title="Third comment", comment_text="I like it!", sess_id=sess_id)) self.assertEqual(['First comment', 'Third comment'], blog.get_comments(post_title="My first post", post_owner="hannamon12", comment_user="******", sess_id=sess_id))
def create_blog(): blog_title = input("Please insert your blog's title: ") blog_author = input("Now please insert your pseudonym: ") new_blog = blog.Blog(blog_title, blog_author) blogs_data[blog_title] = new_blog