def delete(api: Client,
           target_id: str,
           target_type: str,
           parent_id: str = '') -> None:
    """
    Delete a post or comment chosen by the current user
    
    Arguments:
        api (Client) : Object instagram Client
        target_id (str) : Id of the post or comment to delete
        target_type (str) : String that can be post or comment
        parent_id (str) : In the event that a comment is deleted,
                          it stores the id of the post that contains said comment,
                          
    """
    if target_type == 'post':
        result = api.delete_media(media_id=target_id)
    else:
        result = api.delete_comment(media_id=parent_id, comment_id=target_id)

    if result['status'] == 'ok':
        print_write_chatbot(
            f"The {target_type} has been successfully removed!\n",
            color='green',
            attrs_color=['bold'])

    else:
        print_write_chatbot(
            f"The {target_type} could not be removed. Please try again later\n",
            color='red',
            attrs_color=['bold'])
示例#2
0
        except:
            created_at = 0

        try:
            image_url = post["image_versions2"]["candidates"][0]["url"]
        except:
            image_url = ""

        data = (pk, media_id, code, like_count, comment_count, image_url,
                created_at)
        conn.execute(
            "insert into old_posts values (?,?,?,?,?,?,?) ON CONFLICT(id) DO NOTHING",
            data,
        )

    conn.commit()

    old_medias = conn.execute(
        "select media_id, code from old_posts op where id not in (select id from old_posts op2 order by created_at desc limit 120) order by created_at DESC;"
    )
    conn.commit

    for media in old_medias:
        print("%s -> %s" % (media[0], media[1]))
        api.delete_media(media[0])
        sleep(5)

    conn.close()
    os.remove("instagram.db")
    os.remove("posts.json")