예제 #1
0
def blog(postid):
    if postid <= 0:
        return "<h1> 404 Error </h1>"
    elif request.method == "GET":
        return render_template("blog.html", post=utils.get_post(postid), comments=utils.get_comments(postid))
    elif request.form["Submit"] == "Comment":
        postid = utils.new_post(session["username"], comment)
        post = utils.get_post(postid)
        return render_template("/blog/", post)
예제 #2
0
def blog(postid):
    if postid <= 0:
        return "<h1> 404 Error </h1>"
    elif request.method == "GET":
        return render_template("blog.html",
                               post=utils.get_post(postid),
                               comments=utils.get_comments(postid))
    elif request.form["Submit"] == "Comment":
        postid = utils.new_post(session["username"], comment)
        post = utils.get_post(postid)
        return render_template("/blog/", post)
예제 #3
0
파일: blog.py 프로젝트: sub14305k/bs_hw
     def get(self,post_id):

        valid_cookie = self.request.cookies.get('user_id')
        if valid_cookie:
            import globals 
            if globals.users != None:
            
                global time_start_post;
                post = memcache.get(post_id)
                
                if not post:
                    post = utils.get_post(post_id)
                    time_start_post = datetime.datetime.now()
                    utils.cache_permalink(post_id, post, True)
                     
                time_reload = datetime.datetime.now()
                total_time = time_reload - time_start_post
                seconds = total_time.seconds
                sec_time = 'Queried: %s seconds ago' % seconds
                
                if not post:
                    self.error(404)
                    return
        
                self.render("permalink.html", post = post, time = sec_time, user= globals.users)
        else:
            self.redirect('/')
예제 #4
0
파일: blog.py 프로젝트: grimpunch/blog
def home(entries=None):
    if not entries:
        posts_folder = app.template_folder + '/posts'
        entries = []
        posts = utils.get_latest_posts_from_folder(posts_folder=posts_folder)
        for post in posts:
            entries.append(utils.get_post(specificpost=post))

    random_fact = utils.get_random_fact()
    return render_template('home.html', entries=entries, random_fact=random_fact)
예제 #5
0
def editpost(postid=-1):
    if postid < 0:
        return "<h1> 404 Error </h1>"
    elif request.method == "GET":
        return render_template("editpost.html", post=utils.get_post(postid))
    elif request.form["Submit"] == "Update":
        status = utils.modify_post(postid, request.form["post"])
        return redirect("/blog/" + postid)
    elif request.fomr["Submit"] == "Delete":
        utils.remove_post(postid)
        return redirect(url_for("home"))
예제 #6
0
def editpost(postid=-1):
    if postid < 0:
        return "<h1> 404 Error </h1>"
    elif request.method == "GET":
        return render_template("editpost.html", post=utils.get_post(postid))
    elif request.form["Submit"] == "Update":
        status = utils.modify_post(postid, request.form["post"])
        return redirect("/blog/"+postid)
    elif request.fomr["Submit"] == "Delete":
        utils.remove_post(postid)
        return redirect(url_for("home"))
예제 #7
0
def edit(post_id):
    if request.method == 'POST':
        if 'modify' in request.form:
            utils.modify_post(post_id, request.form['new_post'])
        else:
            utils.remove_post(post_id)
        return redirect(url_for('index'))
    if 'username' not in session:
        return redirect(url_for('login'))
    if post_id not in utils.get_user_posts(session['username']):
        return 'Error: Invalid post id.'
    return render_template('edit.html', post=utils.get_post(post_id))
예제 #8
0
def edit(post_id):
	if request.method == 'POST':
		if 'modify' in request.form:
			utils.modify_post(post_id, request.form['new_post'])
		else:
			utils.remove_post(post_id)
		return redirect(url_for('index'))
	if 'username' not in session:
		return redirect(url_for('login'))
	if post_id not in utils.get_user_posts(session['username']):
		return 'Error: Invalid post id.'
	return render_template('edit.html', post=utils.get_post(post_id))
예제 #9
0
    def get(self):
        post = utils.get_post(self.request.path)

        # logging.info("WIKI: Post is: " + str(post))
        # logging.info('WIKI: content: ' + str(post[0].content))

        if self.user and post is None:
            self.redirect('/_edit' + self.request.path)
        else:
            self.set_secure_cookie('ref', self.request.path)
            self.render('wiki.html', post=post)

        logging.info("WIKI: path is: " + self.request.path)
예제 #10
0
    def get(self):
        path = self.getpath()
        #logging.info("Edit path is: " + self.request.path)

        if not self.user:
            self.redirect(path)
        
        self.set_secure_cookie('ref', path)
        #logging.info('EditPage: cookie set.')

        post = utils.get_post(path)
        #logging.info('EDIT: Content = ' + post.content)
        self.render('edit.html', post = post)
예제 #11
0
import vk
import fb
import tgram
import utils

logging.basicConfig(
    filename="post.log",
    filemode="w",
    format="%(asctime)s:%(message)s",
    level=logging.ERROR,
)

directory = utils.get_directory()

try:
    post = utils.get_post(directory)
except FileNotFoundError as error:
    exit(error)
except KeyError as error:
    exit(f"{error} is unsupported file format")

load_dotenv()
try:
    vk.post_to_group(post)
except requests.HTTPError as error:
    logging.error(error)

try:
    fb.post_to_group(post)
except requests.HTTPError as error:
    logging.error(error)
예제 #12
0
def update_table(n_clicks, search_terms, limit, offset):
    input = search_terms

    # ------------- preparing the input -------------

    tokenized_input = utils.get_post(input)
    authors = utils.get_authors(tokenized_input)
    text, important = utils.time_important(utils.get_input(tokenized_input))

    # loading the models + running the query through
    ft_model_title = FastText.load('models/_fasttext_title.model')
    ft_model_author = FastText.load('models/_fasttext_author.model')
    ft_model_categories = FastText.load('models/_fasttext_categories.model')

    query_title = [ft_model_title.wv[vec] for vec in text]
    query_title = np.mean(query_title, axis=0)

    query_author = [ft_model_author.wv[vec] for vec in authors]
    query_author = np.mean(query_author, axis=0)

    query_categories = [ft_model_categories.wv[vec] for vec in text]
    query_categories = np.mean(query_categories, axis=0)

    # searching the query in the title index
    ids_title, distances_title = index_title.knnQuery(query_title, k=10)
    titles_df = df.iloc[ids_title]
    titles_df['distances'] = pd.DataFrame(
        pd.Series(distances_title)).set_index(titles_df.index)
    titles_df.reset_index(inplace=True)
    results = titles_df

    # searching the author in the author index
    if not np.isnan(query_author).any():
        ids_author, distances_author = index_author.knnQuery(query_author,
                                                             k=10)
        authors_df = df.iloc[ids_author]
        authors_df['distances'] = pd.DataFrame(
            pd.Series(distances_author)).set_index(authors_df.index)
        authors_df.reset_index(inplace=True)
        results = pd.concat([authors_df, titles_df])

    # searching categories in the categories index
    ids_categories, distances_categories = index_categories.knnQuery(
        query_categories, k=10)
    categories_df = df.iloc[ids_categories]
    categories_df['distances'] = pd.DataFrame(
        pd.Series(distances_categories)).set_index(categories_df.index)
    categories_df.reset_index(inplace=True)
    results = pd.concat([results, categories_df])  # concat them all together
    results['distances'] = results['distances'].apply(
        lambda x: round(x, 2))  # round the distances

    # sort the dict results by distances
    # if time is important, then dates are given importance; otherwise, they are not considered as important
    if important:
        results = results.sort_values(by=['distances'])[:100]
        dict_results = results.sort_values(
            by=['update_date'])[:10].to_dict('records')

    else:
        dict_results = results.sort_values(
            by=['distances', 'update_date'])[:10].to_dict("records")

    #Create Table
    tbl = dash_table.DataTable(
        id='table',
        style_cell={
            'whiteSpace': 'normal',
            'height': 'auto',
            'textAlign': 'left',
            'font-family': 'sans-serif',
            'overflow': 'hidden',
            'textOverflow': 'ellipsis',
            'maxWidth': 0,
        },
        data=dict_results,
        columns=[
            {
                'name': 'Author',
                'id': 'authors',
                'type': 'text'
            },
            {
                'name': 'Title',
                'id': 'title',
                'type': 'text'
            },
            {
                'name': 'Abstract',
                'id': 'abstract',
                'type': 'string'
            },
            {
                'name': 'Distances',
                'id': 'distances',
                'type': 'numeric'
            },
        ],
        tooltip_delay=0,
        tooltip_duration=None,
        markdown_options={'link_target': '_blank'},
        filter_action='native',
        sort_action='native',
        sort_mode='multi',
        export_format="csv",
    )
    return html.Div([tbl])
예제 #13
0
파일: blog.py 프로젝트: sub14305k/bs_hw
 def get(self, post_id):
     
     post = utils.get_post(post_id)
     self.render_json(post.create_dict())