Пример #1
0
def get_detail(detailurl, fenlei):

    try:
        res = requests.get(detailurl)
        res.encoding = res.apparent_encoding
        selector = etree.HTML(res.text)
        title = selector.xpath("//div[@class='article-head']/h2/text()")
        title = title[0] if title else ''
        content = selector.xpath(
            "//div[@class='article']/div[@class='article-body']")
        content = etree.tostring(content[0], encoding='utf-8').decode()
        content = clean_html(content)
        summary = clean_content(content)
        summary = get_summary(summary)

        if "违者将被依法追究法律责任" not in content:

            if article.count_documents({'link': detailurl}) <= 0:
                article.insert_one({
                    'title': title,
                    'content': content,
                    'summay': summary,
                    'link': detailurl,
                    'tags': get_tags(title, content),
                    'status': 0,
                    'fenlei': fenlei
                })
            else:
                print("链接重复")
            print(title)
    except Exception as e:
        pass
Пример #2
0
def tagging():
	if not users.is_admin():
		return render_template("forbidden.html", message="Sinulla ei ole oikeutta nähdä tätä sivua")
	restaurants_list = restaurants.get_list()
	tags_list = tags.get_tags()
	if request.method == "GET":	
		return render_template("tags.html", tags=tags_list, restaurants=restaurants_list)
	if request.method == "POST":
		written_tag = request.form["tag"]
		list_tag = request.form["existing_tag"]
		if is_empty(written_tag) and is_empty(list_tag):
			return render_template("tags.html", errormessage="Et lisännyt tägiä", tags=tags_list, restaurants=restaurants_list)
		elif not is_empty(written_tag) and not is_empty(list_tag):
			return render_template("tags.html", errormessage="Lisää yksi tägi kerrallaan", tags=tags_list, restaurants=restaurants_list)
		else:
			tag_to_be_added = ""
			if is_empty(written_tag):
				tag_to_be_added = list_tag
			else:
				tag_to_be_added = written_tag
			if len(tag_to_be_added) > 50:
				return render_template("tags.html", errormessage="Tägi on liian pitkä. Sen tulee olla alle 50 merkkiä", tags=tags_list, restaurants=restaurants_list) 
			if "selected_restaurants" in request.form:
				restaurants_to_be_added = request.form.getlist("selected_restaurants")
				check_csfr(request.form["csrf_token"], users.get_csrf())
				tags.add_tags(restaurants_to_be_added, tag_to_be_added)
			else:
				return render_template("tags.html", errormessage="Et antanut ravintoloita", tags=tags_list, restaurants=restaurants_list)
		return redirect("/")
Пример #3
0
def login():
	username = request.form["username"]
	password = request.form["password"]
	if users.login(username, password):
		return redirect("/")
	else:
		tag_list = tags.get_tags()
		return render_template("index.html", errormessage="Väärä tunnus tai salasana.", tags=tag_list)
Пример #4
0
	def get_tags(self):
		if self._tags == None:
			try:
				self._tags = tags.get_tags(self.name)
			except HeaderNotFoundError, e:
				raise HFileException(str(e))
			except MP4StreamInfoError, e:
				raise HFileException(str(e))
Пример #5
0
def fill_album_from_tags(basepath):
    for file in files(basepath):
        filepath = basepath + file
        artist, title = tags.get_tags(filepath)
        album = get_album(artist, title)

        if album:
            print(artist, title, album)
            tags.set_tags(filepath, album=album)
    def do_GET(self):
        self._set_headers(200)
        response = {}

        # Parse URL and store entire tuple in a variable
        parsed = self.parse_url(self.path)

        if len(parsed) == 2:
            (resource, id) = parsed

            if resource == "categories" and id is None:
                response = get_categories()
            if resource == "tags":
                response = get_tags()
            if resource == "reactions":
                response = get_reactions()
            if resource == "tagPosts" and id is None:
                response = get_tagPosts()
            if resource == "subscriptions" and id is None:
                response = get_subscriptions()
            if resource == "posts":
                if id is not None:
                    response = get_single_post(id)
                else:
                    response = get_all_posts()

            if resource == "tagPosts" and id is None:
                response = get_tagPosts()

            if resource == "reactionPosts" and id is None:
                response = get_reactionPosts()
            if resource == "users":
                if id is not None:
                    response = get_single_user(id)
                else:
                    response = get_all_users()

        elif len(parsed) == 3:
            (resource, key, value) = parsed

            if key == "email" and resource == "users":
                response = get_user_by_email(value)

            if key == "category_id" and resource == "posts":
                response = get_posts_by_category_id(value)

            if key == "user_id" and resource == "posts":
                response = get_posts_by_user_id(value)

            if key == "tag_id" and resource == "posts":
                response = get_posts_by_tag_id(value)
            if key == "post_id" and resource == "tags":
                response = get_single_post_tags(value)

        self.wfile.write(response.encode())
Пример #7
0
def inject_tags():
    all_tags = tags.get_tags()
    n = 1
    all_tags_dicts = []
    for tag in all_tags:
        all_tags_dicts.append(
            {
                'id': n,
                'name': tag,
            }
        )
        n += 1

    encoded_tags = json.dumps(all_tags_dicts)
    return dict(all_tags=encoded_tags)
Пример #8
0
def show_case_settings(case_id):
    """Shows user settings for chosen case"""

    # check if the user has permission to view this case
    user_permitted = validate_usercase(case_id, g.current_user.user_id)

    case = Case.query.get(case_id)
    owner_id = case.owner_id
    owner = User.query.get(owner_id)

    if user_permitted:
        # get all users associated with this case id
        users = db.session.query(User.fname, User.lname, User.email,
                                 User.user_id).join(UserCase).filter(
                                     UserCase.case_id == case_id).order_by(
                                         User.fname).all()

        # get the tags for this case and the default tags
        tags = get_tags(case_id)

        tag_counts = {}

        for tag in tags:
            # get tagged clips returns a list of clip ids - convert to a string
            # and it will be used as a value on a download link
            tag.matching_clips = get_tagged_clips(tag, case_id)

            # count the clip ids to get a total count
            tag_counts[tag.tag_name] = len(tag.matching_clips)

            # convert the list to a string to use as a value on the button
            # we do this bc the handle-clips route parses a string into a
            tag.matching_clips = str(tag.matching_clips)[1:-1]

        case_mess = CaseMessage.query.filter(
            CaseMessage.case_id == case_id).order_by(
                CaseMessage.mess_id.desc()).all()

        return render_template('case-settings.html',
                               users=users,
                               case=case,
                               tags=tags,
                               owner=owner,
                               tag_counts=tag_counts,
                               case_mess=case_mess)
    else:
        flash("You don't have permission to view that case")
        return redirect('/cases')
Пример #9
0
def tag(tag=None):
    if request.method == 'POST':
        return process_post()
    if not tag:
        tag_names = tags.get_tags()
    else:
        tag_names = [tag]
    gifs = tags.get_images_for_tag(tag)
    gif_payload = tags.get_tags_for_images(gifs)
    gif_tags = dict((d, gif_payload[d]['data']) for d in gif_payload)
    gif_meta = _format_meta_for_gif_payload(gif_payload)

    return render_template(
        'tags.html',
        gifs=gifs,
        tags=tag_names,
        gif_tags=gif_tags,
        gif_meta=gif_meta,
    )
Пример #10
0
def process_get(page):
    num = int(request.args.get('num', 10))
    gifs = get_file_paths()
    pagination = Pagination(page, num, len(gifs))
    if not gifs and page != 1:
        abort(404)

    start = page * num - num
    gif_payload = tags.get_tags_for_images(gifs)
    gif_tags = dict((d, gif_payload[d]['data']) for d in gif_payload)
    gif_meta = _format_meta_for_gif_payload(gif_payload)
    return render_template(
        'index.html',
        pagination=pagination,
        tags=sorted(tags.get_tags()),
        gifs=gifs[start:start + num],
        gif_tags=gif_tags,
        gif_meta=gif_meta,
    )
Пример #11
0
def show_all_clips(vid_id):
    """loads page with a list of all clips for that vid id"""

    #get a list of all the clips associated with that video id
    main_vid = Video.query.get(vid_id)
    case_id = main_vid.case.case_id

    user_permitted = validate_usercase(case_id, g.current_user.user_id)

    if user_permitted:
        clips = Clip.query.filter(Clip.vid_id == vid_id).all()

        for clip in clips:
            # get the clip duration
            # if the time includes milliseconds - trim them off
            if clip.start_at is not None:
                start_time = clip.start_at
                if len(start_time) > 8:
                    clip.start_at = start_time = start_time[:-4]

                end_time = clip.end_at
                if len(end_time) > 8:
                    clip.end_at = end_time = end_time[:-4]

                start_at = datetime.strptime(start_time, '%H:%M:%S')
                end_at = datetime.strptime(end_time, '%H:%M:%S')

                clip.duration = end_at - start_at
            else:
                clip.duration = '--'

        # get the tags for this case and the default tags
        tags = get_tags(main_vid.case_id)

        return render_template('vid-clips.html',
                               main_vid=main_vid,
                               clips=clips,
                               tags=tags)
    else:
        flash("You don't have permission to view that case")
        return redirect('/cases')
Пример #12
0
    def __init__(self, *args, **kwargs):
        super(FormTags, self).__init__(*args, **kwargs)

        if self.instance.id:
            self.initial['tags'] = get_tags(self.instance)
Пример #13
0
def inject_tags_by_letter():
    return _subdivide_tags(tags.get_tags())
Пример #14
0
def main():
    tags = get_tags(sys.argv[1])
    for item in get_tags_iter(sys.argv[1], tags):
        print ",".join(item)
Пример #15
0
 def setUp(self):
     self.tags = get_tags()
Пример #16
0
 def req_tag_list(self):
     return tags.get_tags()
Пример #17
0
def bmarks():
    return_data = get_tags()
    return return_data
Пример #18
0
 def setUp(self):
     self.tags = get_tags()
Пример #19
0
import extract
import tags
import tweets

if __name__ == "__main__":
	print("Don't forget to chcp 65001") # this is a reminder to me when I run this program from command line
	print('Enter your query')
	query = input()

	list_of_tags = tags.get_tags(query)

	list_of_tweets = tweets.get_tweets(list_of_tags)

	result = extract.get_codes(list_of_tweets)

	for code in result:
		print (code)


	r = extract.get_likely_tweets(list_of_tweets)
	for t in r:
		print(t)
Пример #20
0
def index():
	tag_list = tags.get_tags()
	return render_template("index.html", tags=tag_list)
Пример #21
0
#!/usr/bin/env python3

import os
import fileinput

from tags import get_tags

tags = get_tags()

code = os.system('git checkout master')

with open('Dockerfile.in') as infile:
    lines = infile.readlines()
    first_line = lines[0].strip()

for t in tags:
    code = os.system('git checkout -b ' + t)
    head_line = first_line + ":" + t + '\n'
    lines[0] = head_line
    with open('Dockerfile', 'w') as outfile:
        outfile.writelines(lines)
    code = os.system('rm -rf __pycache__ & git add . && git commit  -m "' + t +
                     '"')

code = os.system('git checkout master')