automated_youtube_channel icon indicating copy to clipboard operation
automated_youtube_channel copied to clipboard

NameError: name 'Username' is not defined

Open damibal opened this issue 3 years ago • 6 comments

Hello Nathan,

In the first time thank you very much for give us help and for the code.

I need help to make it working.... I fill in config.py, main.py, scrape_videos.py like:

config.py:

IG_USERNAME = danibal IG_PASSWORD = xxxxxxx

main.py:

................................................

num_to_month = { 1: "Jan", 2: "Feb", 3: "Mar", 4: "Apr", 5: "May", 6: "June", 7: "July", 8: "Aug", 9: "Sept", 10: "Oct", 11: "Nov", 12: "Dec" }

USER VARIABLES FILL THESE OUT (fill out username and password in config.py)

IG_USERNAME = config.IG_USERNAME IG_PASSWORD = config.IG_PASSWORD print(IG_USERNAME....? Here i have to complete?) print(IG_PASSWORD....and here?) title = "TRY NOT TO LAUGH (BEST Dank video memes) V1" now = datetime.datetime.now() videoDirectory = "./DankMemes_" + num_to_month[now.month].upper() + "_" + str(now.year) + "V" + str(now.day) + "/" outputFile = "./" + num_to_month[now.month].upper() + "" + str(now.year) + "_v" + str(now.day) + ".mp4"

INTRO_VID = '' # SET AS '' IF YOU DONT HAVE ONE OUTRO_VID = '' TOTAL_VID_LENGTH = 13*60 MAX_CLIP_LENGTH = 19 MIN_CLIP_LENGTH = 5 DAILY_SCHEDULED_TIME = "20:00" TOKEN_NAME = "token.json"

Setup Google

SCOPES = ["https://www.googleapis.com/auth/youtube.upload"] os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" client_secrets_file = "googleAPI.json"

def routine():

# Handle GoogleAPI oauthStuff
print("Handling GoogleAPI")
creds = None
# The file token1.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists(TOKEN_NAME):
    creds = Credentials.from_authorized_user_file(TOKEN_NAME, SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            client_secrets_file, SCOPES)
        creds = flow.run_console()
    # Save the credentials for the next run
    with open(TOKEN_NAME, 'w') as token:
        token.write(creds.to_json())

googleAPI = build('youtube', 'v3', credentials=creds)

now = datetime.datetime.now()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)

#metadataFile = "./metadata-" + num_to_month[now.month].upper() + "_" + str(now.year) + "_v" + str(now.day) + ".txt"
description = ""
print(outputFile)

if not os.path.exists(videoDirectory):
    os.makedirs(videoDirectory)

# Step 1: Scrape Videos
print("Scraping Videos...")
scrapeVideos(username = danibal,
             password = xxxxxxxxx,
             output_folder = videoDirectory,
              days=1)
print("Scraped Videos!")

description = "Enjoy the memes! :) \n\n" \
"like and subscribe to @Chewy for more \n\n" \

# Step 2: Make Compilation
print("Making Compilation...")
makeCompilation(path = videoDirectory,
                introName = INTRO_VID,
                outroName = OUTRO_VID,
                totalVidLength = TOTAL_VID_LENGTH,
                maxClipLength = MAX_CLIP_LENGTH,
                minClipLength = MIN_CLIP_LENGTH,
                outputFile = outputFile)
print("Made Compilation!")

description += "\n\nCopyright Disclaimer, Under Section 107 of the Copyright Act 1976, allowance is made for 'fair use' for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use.\n\n"
description += "#memes #dankmemes #compilation #funny #funnyvideos \n\n"

# Step 3: Upload to Youtube
print("Uploading to Youtube...")
uploadYtvid(VIDEO_FILE_NAME=outputFile,
            title=title,
            description=description,
            googleAPI=googleAPI)
print("Uploaded To Youtube!")

# Step 4: Cleanup
print("Removing temp files!")
# Delete all files made:
#   Folder videoDirectory
shutil.rmtree(videoDirectory, ignore_errors=True)
#   File outputFile
try:
    os.remove(outputFile)
except OSError as e:  ## if failed, report it back to the user ##
    print ("Error: %s - %s." % (e.filename, e.strerror))
print("Removed temp files!")

def attemptRoutine(): while(1): try: routine() break except OSError as err: print("Routine Failed on " + "OS error: {0}".format(err)) time.sleep(60*60)

#attemptRoutine() schedule.every().day.at(DAILY_SCHEDULED_TIME).do(attemptRoutine)

attemptRoutine() while True: schedule.run_pending()
time.sleep(60) # wait one min

SCRAPE_VIDEOS.PY:

import datetime import dateutil.relativedelta from instalooter.looters import InstaLooter, ProfileLooter import instaloader from instalooter.cli.login import login

scrape_videos.py scrapes all the videos from pages we are following

def scrapeVideos(username = "", password = "", output_folder = "", days = 1):

print("Starting Scraping")

L = instaloader.Instaloader()

# Login or load session for loader
L.login(username, password)  
profile = instaloader.Profile.from_username(L.context, username)
following = profile.get_followees()
print(following)

today = datetime.date.today()
timeframe = (today, today - dateutil.relativedelta.relativedelta(days=days))

for profile in following:
    acc = profile.username
    looter = ProfileLooter(acc, videos_only=True, template="{id}-{username}-{width}-{height}")
    if not looter.logged_in():
        looter.login(username, password)
    print("Scraping From Account: " + acc)
    try:
        numDowloaded = looter.download(output_folder, media_count=30, timeframe=timeframe)
        print("Downloaded " + str(numDowloaded) + " videos successfully")
        print("")
    except Exception as e:
        print("Skipped acc " + acc + "because of");
        print(e);

if name == "main": scrapeVideos(username = danibal, password = XXXXXXX, output_folder = "./Memes_December_4")

I received this Error:

NameError: name 'Danibal' is not defined

Please let me know whats happening.

Regards, Daniel

damibal avatar May 21 '21 15:05 damibal

did you try to write "danibal"? Instagram's usernames can't have uppercases.

agustdaegu avatar May 22 '21 21:05 agustdaegu

Hello Agustdaegu...I try it but the same error..maybe in some line something missing

Thank you very much

damibal avatar May 22 '21 21:05 damibal

hello i tried the code it worked good a couple of times but now the instaloader is giving the error user not found fir every acc.

sridharmani0510 avatar May 23 '21 10:05 sridharmani0510

Hello...I have tried with another user and I have the same problem ... I am changing things to see if I make the code work ... the last error gives me about the password "syntax error" in scrape_videos.py

damibal avatar May 23 '21 12:05 damibal

I bet this is because you are incorrectly defining your string variables in config.py, you must define them as strings with quotes. So like this: IG_USERNAME = "danibal" IG_PASSWORD = "xxxxxxx"

jasongwaley182 avatar May 23 '21 14:05 jasongwaley182

Hello Jason...the problem was the quotes...I resolve it...thank you very much for your help...now I have some problems in google credentials but I will resolve it.

Best regards to all that written me and thank you very much

damibal avatar May 23 '21 16:05 damibal