def scrape_article_name(article_id):
    article = db.get_article(article_id)
    if article == None:
        print('There is no article with that ID. article NOT found.\n')
    else:
        print()
        display_single_article(article, str(article.ArticleID))
        article_choice = btc.read_int_ranged(
            '1 to rescrape title, 2 to leave as is: ',
            min_value=1,
            max_value=2)
        if article_choice == 1:
            try:
                new_article_news_item = na.get_article_from_url(article.link)
                new_title = new_article_news_item.title
                print('''
New title: {0}
Old title: {1}'''.format(new_title, article.name))
            except:
                new_title = 'Title scrape failed'
            title_choice = btc.read_int_ranged(
                '1 to replace title, 2 to keep original title: ',
                min_value=1,
                max_value=2)
            if title_choice == 1:
                db.update_article_name(article_id, new_title)
            elif title_choice == 2:
                print('article update cancelled')

        elif article_choice == 2:
            print('article update cancelled')
def update_article_description(article_id):
    article = db.get_article(article_id)
    if article == None:
        print("There is no article with that ID. article NOT found.\n")
    else:
        print()
        display_single_article(article, str(article.ArticleID))
        article_choice = btc.read_int_ranged(
            '1 to edit article description, 2 to leave as is: ',
            min_value=1,
            max_value=2)
        if article_choice == 1:
            description_choice = btc.read_text(
                'View article description? y/n: ')
            if description_choice == 'y':
                article_summary = na.get_article_summary(article.link)
                print(article_summary)
            new_description = btc.read_text(
                'Enter new description or "." to cancel: ')

            if new_description != '.':
                db.update_article_description(article_id, new_description)
                print('Article description updated.\n')
            else:
                print('Edit cancelled, article description unchanged')
        else:
            print('Edit cancelled, article description unchanged')
Beispiel #3
0
 def index(self):
   try:
     article = get_article("index")
     data = {"content": textile(article["content"]),
             "title": article["title"]}
   except ErrorNoSuchRecord as not_found_err:
     data = {"content": textile(open("readme.textile").read())}
   self.response = Template.render(filename="index.html", **data)
def display_article_by_id(article_id=None):
    if not article_id:
        article_id = input("Article ID: ")
    article = db.get_article(article_id)
    if article == None:
        print("There is no article with that ID. article NOT found.\n")
    else:
        print()
        display_single_article(article, str(article.ArticleID))
Beispiel #5
0
 def article(self, slug):
   try:
     article = get_article(slug)
     data = {"title": article["title"],
             "slug": slug,
             "content": textile(article["content"])}
     self.response = Template.render(filename="article.html", **data)
   except ErrorNoSuchRecord as not_found_err:
     self.not_found(slug)
def delete_article(article_id):
    try:
        article = db.get_article(article_id)
        choice = input("Are you sure you want to delete '" + article.name +
                       "'? (y/n): ")
        if choice == "y":
            db.delete_item(article_id, item_type='article')
            print("'" + article.name + "' was deleted from database.\n")
        else:
            print("'" + article.name + "' was NOT deleted from database.\n")
    except AttributeError as e:
        print(e, 'Article id not found')
Beispiel #7
0
 def edit(self, slug):
   if self.is_post():
     self._save()
   else:
     try:
       article = get_article(slug)
       data = {"title": article["title"],
               "content": article["content"],
               "slug": slug}
     except ErrorNoSuchRecord as not_found_err:
       data = {"title": "New article: %s" % (slug,),
               "content": "Fill this field in with information. " \
                           "Textile is alright.",
               "slug": slug}
     self.response = Template.render(filename="edit.html", **data)
def update_article_author(article_id):
    article = db.get_article(article_id)
    if article == None:
        print("There is no article with that ID. article NOT found.\n")
    else:
        print()
        display_single_article(article, str(article.ArticleID))
        article_choice = btc.read_int_ranged(
            '1 to edit article author, 2 to leave as is: ',
            min_value=1,
            max_value=2)
        if article_choice == 1:
            new_author = btc.read_text(
                'Enter new author name or . to cancel: ')
            if new_author != '.':
                db.update_article_author(article_id, new_author)
        else:
            print('Edit cancelled, article title unchanged')
Beispiel #9
0
def get_csv_data(cursor, published_articles, journal_code):

	records = []
	
	for pub_article in published_articles:
		article = db.get_article(cursor, pub_article.get('article_id'))

		doi = article['settings'].get('pub-id::doi')

		if doi:
			authors = db.get_authors(cursor, pub_article.get('article_id'))

			author_emails = []
			for author in authors:
				if not author.get('email') in settings.EXCLUDED_EMAILS and not author.get('email') in author_emails:
					author_emails.append(author.get('email'))
					row = build_csv_row(doi, author)
					records.append(row)

	return records
def update_article_name(article_id):
    article = db.get_article(article_id)
    if article == None:
        print("There is no article with that ID. article NOT found.\n")
    else:
        print()
        display_single_article(article, str(article.ArticleID))
        article_choice = btc.read_int_ranged(
            '1 to edit article title, 2 to leave as is: ',
            min_value=1,
            max_value=2)
        if article_choice == 1:
            try:
                newsItem1 = na.get_article_from_url(article.link)
                updated_title = newsItem1.title
            except Exception as e:
                print('Scrape failed because of {0}'.format(e))
                updated_title = 'Invalid'
            print('Rescraped title: {0}'.format(updated_title))
            title_choice = btc.read_int_ranged(
                '1 - existing title, 2 - scraped title, 3 - manual input: ', 1,
                3)

            if title_choice == 1:
                print('Title update cancelled, article title unchanged.')
                return
            elif title_choice == 2:
                db.update_article_name(article_id, updated_title)
                print('Title update complete. Return to main menu.')
            elif title_choice == 3:
                new_title = btc.read_text('Enter new title or . to cancel: ')
                if new_title != '.':
                    db.update_article_name(article_id, new_title)
                else:
                    print('Edit cancelled, return to main menu')
                    return
        else:
            print('Edit cancelled, article title unchanged')
def update_article_category(article_id):
    article = db.get_article(article_id)
    if article == None:
        print("There is no article with that ID. article NOT found.\n")
    else:
        print()
        display_single_article(article, str(article.ArticleID))
        article_choice = btc.read_int_ranged(
            '1 to edit article category, 2 to leave as is: ',
            min_value=1,
            max_value=2)
        if article_choice == 1:
            new_category_id = btc.read_int('Enter new category_id: ')
            result = db.get_category(new_category_id)
            #Add in some text that is displayed to make it clear that the category is being updated
            if result == None:
                print(
                    'There is no category with that ID, article category NOT updated.\n'
                )
            else:
                db.update_article_category(article_id, new_category_id)
        else:
            print('Edit cancelled, article title unchanged')
def update_article_date(article_id):
    article = db.get_article(article_id)
    if article == None:
        print("There is no article with that ID. article NOT found.\n")
    else:
        print()
        display_single_article(article, str(article.ArticleID))
        article_choice = btc.read_int_ranged(
            '1 to edit article date, 2 to leave as is: ',
            min_value=1,
            max_value=2)
        if article_choice == 1:
            new_date = btc.read_date('Enter new date: ')
            date_choice = btc.read_int_ranged(
                '1 to change date to: {0}, 2 to cancel: '.format(new_date),
                min_value=1,
                max_value=2)
            if date_choice == 1:
                db.update_article_date(article_id, new_date)
                print('Update complete.\n')
            elif date_choice == 2:
                print('Edit cancelled, article date unchanged')
        else:
            print('Edit cancelled, article date unchanged')
Beispiel #13
0
    def get(self, page):

        # 校验身份
        if self.check_login() == False:
            self.redirect("/login")
            return

            # 处理请求页面
        if 1 == 1:

            if page == "index":
                self.MyRender(admin_dir("%s.html" % page), classify=db.get_classify())

                # 文章管理
            elif page == "articles":
                self.MyRender(admin_dir("%s.html" % page), articles=db.get_article())

                # 更新文章
            elif page == "update":

                id = self.get_argument("id")
                self.MyRender(
                    admin_dir("%s.html" % page), classify=db.get_classify(), article=db.get_atcbyid(id, True), id=id
                )

                # 评论管理
            elif page == "comments":

                self.MyRender(admin_dir("%s.html" % page), comments=db.get_comments())

                # 留言管理
            elif page == "guests":

                self.MyRender(admin_dir("%s.html" % page), guests=db.get_guest())

                # 留言管理
            elif page == "links":

                self.MyRender(admin_dir("%s.html" % page), links=db.get_links())

                # 分类管理

            elif page == "classify":

                self.MyRender(admin_dir("%s.html" % page), classify=db.get_classify())

                # 分类管理

            elif page == "upload":

                self.MyRender(admin_dir("%s.html" % page))

                # 博客配置
            elif page == "options":

                self.MyRender(admin_dir("%s.html" % page), templates=os.listdir(cur_dir() + "templates"))

                # 返回自定义页面
            else:
                # self.MyRender(admin_dir("%s.html" % page))
                self.redirect("/login")
        else:
            self.redirect("/login")