Ejemplo n.º 1
0
def save_media(params):
    query = Media.insert(params).on_conflict(conflict_target=[Media.source],
                                             update=params)
    query.execute()

    mark_processed(params['source'])

    return Media.select().where(Media.digest == params['digest']).execute()[0]
Ejemplo n.º 2
0
def deduplicate():
    gold = Media.select(
        peewee.fn.first_value(Media.id).over(
            partition_by=Media.digest,
            order_by=[
                Media.organized_at.asc(nulls='LAST'),
                peewee.fn.length(Media.stem).asc(),
                Media.taken_at.asc()
            ]).distinct())

    with Media.db:
        Media.update(duplicate=False).execute()
        Media.update(duplicate=True).where(Media.id.not_in(gold)).execute()
Ejemplo n.º 3
0
def organize(args, pool, log):
    photos = Media.select()\
        .where(Media.organized_at.is_null(), ~Media.duplicate)\
        .order_by(Media.id.asc())

    for parent in set(pathlib.Path(photo.path).parent for photo in photos):
        parent.mkdir(parents=True, exist_ok=True)

    for photo in photos:
        photo.organized_at = datetime.datetime.now()
        photo.save()
        source = pathlib.Path(photo.source)
        try:
            source.rename(photo.path)
            print('mv:', photo.source, photo.path)
        except FileNotFoundError as e:
            print('error:', str(e))
Ejemplo n.º 4
0
def get_all_media():

	try:
		all_media = [ model_to_dict(media, exclude=[Media.user_id.password]) for media in Media.select()]

		for media in all_media:
			comments = Comment.select().where(Comment.media_id == media['id'])
			comments_dict = [model_to_dict(comment, exclude=[Comment.user_id.password]) for comment in comments]
			media['comments'] = comments_dict

			favorites = Favorite.select().where(Favorite.media_id == media['id'])
			favorites_dict = [model_to_dict(favorite, exclude=[Comment.user_id.password]) for favorite in favorites]
			media['favorites'] = favorites_dict



		return jsonify(data=all_media, status={"code": 200, "message": "Success"})

	except Media.DoesNotExist:
		return jsonify(data={}, status={"code": 401, "message": "There was an error getting the resource"})
Ejemplo n.º 5
0
def main():
    logging.basicConfig(format='%(levelname)s:%(message)s',
                        level=logging.DEBUG)
    url = 'http://feeds.feedburner.com/descargas2020new'

    feed = feedparser.parse(url)

    posts = []

    for post in feed.entries:
        post = Post(post.title, post.link)
        posts.append(post)
        #logging.info(post)

    for post in posts:
        contar = (Media.select().where(Media.url == post.url).count())
        if contar == 0:
            scrapingRssPost(post)
            notificar.notificar(post.title)
        else:
            break
Ejemplo n.º 6
0
def show_user(id):

    try:

        user = User.get_by_id(id)

        medias = Media.select().where(Media.user_id == id)

        medias_dict = [model_to_dict(media) for media in medias]

        for media in medias_dict:
            comments = Comment.select().where(Comment.media_id == media['id'])
            comments_dict = [
                model_to_dict(comment, exclude=[Comment.user_id.password])
                for comment in comments
            ]
            media['comments'] = comments_dict

            favorites = Favorite.select().where(
                Favorite.media_id == media['id'])
            favorites_dict = [
                model_to_dict(favorite, exclude=[Favorite.user_id.password])
                for favorite in favorites
            ]
            media['favorites'] = favorites_dict

        favorites = Favorite.select().where(Favorite.user_id == id)

        favorites_media = [favorite.media_id for favorite in favorites]

        fav_dict = [model_to_dict(favorite) for favorite in favorites_media]

        for fav in fav_dict:
            comments = Comment.select().where(Comment.media_id == fav['id'])
            comments_dict = [
                model_to_dict(comment, exclude=[Comment.user_id.password])
                for comment in comments
            ]
            fav['comments'] = comments_dict

            favorites = Favorite.select().where(Favorite.media_id == fav['id'])
            favorites_dict = [
                model_to_dict(favorite, exclude=[Favorite.user_id.password])
                for favorite in favorites
            ]
            fav['favorites'] = favorites_dict

        user_dict = model_to_dict(user)

        user_dict['posted_media'] = medias_dict
        user_dict['favorited_media'] = fav_dict

        del user_dict['password']

        # 	#################
        # 	# Need to join with users posted media (with comments and fav counts), plus join to user's favorited media (with comments, fav counts). Also, comments need to join with user to associate username with each comment.
        # 	#################

        return jsonify(data=user_dict,
                       status={
                           'code': 200,
                           'message': 'User found on resource.'
                       })

    except User.DoesNotExist:

        return jsonify(data={},
                       status={
                           'code': 401,
                           'message': 'User not found on resource.'
                       })