Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
isPique authored Oct 29, 2023
1 parent c81a233 commit 7d602c7
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Scripts/highlights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import instaloader
import os

instance = instaloader.Instaloader()

# Personal account is not recommended. To use it, simply create a new account.
username = "YOUR INSTAGRAM USERNAME HERE"
password = "YOUR INSTAGRAM PASSWORD HERE"

instance.compress_json = False

# Check if you have a session file to load, if not, login using credentials
try:
instance.load_session_from_file(username, "cookies.txt")

except FileNotFoundError:
try:
instance.login(username, password)

except:
# If login fails, load the session using sessionid and csrftoken (not recommended if you use VPN)
instance.load_session(username, {"sessionid": "YOUR SESSION ID HERE", "csrftoken": "YOUR CSRFTOKEN HERE"})

# Save the session to a file for future use
instance.save_session_to_file("cookies.txt")

if instance.context.is_logged_in:
print(f"Logged as {username}")

else:
print("An error occurred while logging into the account.")

# Enter the username with the highlights you want to download
user = ""
profile = instaloader.Profile.from_username(instance.context, username = user)

os.makedirs(user, exist_ok = True)
os.chdir(user)

# Get the user's highlights and download them
for highlight in instance.get_highlights(user = profile):
for item in highlight.get_items():
instance.download_storyitem(item, '{}/{}'.format(highlight.owner_username, highlight.title))

# Delete unwanted files
def delete_files_with_specific_extensions(folder_path, extensions):
for root_folder, _, files in os.walk(folder_path):
for file in files:
file_extension = file.split(".")[-1]
if file_extension in extensions:
file_path = os.path.join(root_folder, file)
try:
os.remove(file_path)
print(f"{file_path} deleted.")
except Exception as e:
print(f"Error occurred while deleting {file_path}: {e}")

os.chdir("..")
folder_path = user
extensions = ["xz", "txt", "json"]

delete_files_with_specific_extensions(folder_path, extensions)
59 changes: 59 additions & 0 deletions Scripts/posts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import instaloader
import os

instance = instaloader.Instaloader()

# Personal account is not recommended. To use it, simply create a new account.
username = "YOUR INSTAGRAM USERNAME HERE"
password = "YOUR INSTAGRAM PASSWORD HERE"

instance.compress_json = False

# Check if you have a session file to load, if not, login using credentials
try:
instance.load_session_from_file(username, "cookies.txt")

except FileNotFoundError:
try:
instance.login(username, password)

except:
# If login fails, load the session using sessionid and csrftoken (not recommended if you use VPN)
instance.load_session(username, {"sessionid": "YOUR SESSION ID HERE", "csrftoken": "YOUR CSRFTOKEN HERE"})

# Save the session to a file for future use
instance.save_session_to_file("cookies.txt")

if instance.context.is_logged_in:
print(f"Logged as {username}")

else:
print("An error occurred while logging into the account.")

while True:
username = input("Enter any username you want: ")
print("The account you are looking for is being searched in Instagram's database..")

try:
try:
profile = instaloader.Profile.from_username(instance.context, username)
if profile and profile.mediacount > 0:
print("Account found. Downloading posts.. ")
instance.download_profile(username)
print("The download process has been completed.")

# Delete unwanted files
for root, dirs, files in os.walk(username):
for file in files:
if file.endswith((".xz", ".txt", ".json")):
os.remove(os.path.join(root, file))
print(f"Deleting: {file}")

elif profile and profile.mediacount == 0:
print("There are no posts in the account you are looking for.")

except instaloader.exceptions.PrivateProfileNotFollowedException:
print("This is a private account. You need to follow it to access its posts.")

except instaloader.exceptions.ProfileNotExistsException:
print("The account you are looking for is not exists on instagram. Try another username")
42 changes: 42 additions & 0 deletions Scripts/saved_posts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import instaloader
import os

instance = instaloader.Instaloader()

# Personal account is not recommended. To use it, simply create a new account.
username = "YOUR INSTAGRAM USERNAME HERE"
password = "YOUR INSTAGRAM PASSWORD HERE"

instance.compress_json = False

# Check if you have a session file to load, if not, login using credentials
try:
instance.load_session_from_file(username, "cookies.txt")

except FileNotFoundError:
try:
instance.login(username, password)

except:
# If login fails, load the session using sessionid and csrftoken (not recommended if you use VPN)
instance.load_session(username, {"sessionid": "YOUR SESSION ID HERE", "csrftoken": "YOUR CSRFTOKEN HERE"})

# Save the session to a file for future use
instance.save_session_to_file("cookies.txt")

if instance.context.is_logged_in:
print(f"Logged as {username}")

else:
print("An error occurred while logging into the account.")

profile = instaloader.Profile.from_username(instance.context, username)

instance.download_saved_posts()

# Delete unwanted files
for root, dirs, files in os.walk(username):
for file in files:
if file.endswith((".xz", ".txt", ".json")):
os.remove(os.path.join(root, file))
print(f"Deleting: {file}")
77 changes: 77 additions & 0 deletions Scripts/stories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from urllib3 import exceptions
from retrying import retry
import instaloader
import requests
import os

instance = instaloader.Instaloader()

# Personal account is not recommended. To use it, simply create a new account.
username = "YOUR INSTAGRAM USERNAME HERE"
password = "YOUR INSTAGRAM PASSWORD HERE"

instance.compress_json = False

# Check if you have a session file to load, if not, login using credentials
try:
instance.load_session_from_file(username, "cookies.txt")

except FileNotFoundError:
try:
instance.login(username, password)

except:
# If login fails, load the session using sessionid and csrftoken (not recommended if you use VPN)
instance.load_session(username, {"sessionid": "YOUR SESSION ID HERE", "csrftoken": "YOUR CSRFTOKEN HERE"})

# Save the session to a file for future use
instance.save_session_to_file("cookies.txt")

if instance.context.is_logged_in:
print(f"Logged as {username}")

else:
print("An error occurred while logging into the account.")

while True:
username = input("Enter any username you want: ")
print("The account you are looking for is being searched in Instagram's database..")

try:
try:
try:
profile = instaloader.Profile.from_username(instance.context, username)
if profile and profile.has_viewable_story:
print("Account found. Downloading stories.. ")
for story in instance.get_stories(profile.username):
for item in story.get_items():
instance.download_storyitem(item, ':stories')
print("The download process has been completed.")

# Delete unwanted files
for root, dirs, files in os.walk(username):
for file in files:
if file.endswith((".xz", ".txt", ".json")):
os.remove(os.path.join(root, file))
print(f"Deleting: {file}")

elif profile and not profile.has_viewable_story:
print("There are no viewable story in the account you are looking for.")

except exceptions.ConnectTimeoutError:
@retry(wait_exponential_multiplier = 1000, wait_exponential_max = 10000, stop_max_attempt_number = 5)
def make_api_request():
response = requests.get(f"https://i.instagram.com/api/v1/users/web_profile_info/?username={username}")
response.raise_for_status()
return response.json()

try:
data = make_api_request()
except Exception as e:
print(f"Error: {e}")

except instaloader.exceptions.PrivateProfileNotFollowedException:
print("This is a private account. You need to follow it to access its stories.")

except instaloader.exceptions.ProfileNotExistsException:
print("The account you are looking for is not exists on instagram. Try another username")

0 comments on commit 7d602c7

Please sign in to comment.