Reputation:
I am trying to pass over a file from the command line to use in my python code, I am using the command like so:
C:\xampp\htdocs\py>twitter_checker.py -u C:\xampp\htdocs\py\test.txt
Now when I run that command I get the following error
usage: twitter_checker.py [-h] u
twitter_checker.py: error: too few arguments
How can I fix this so I can pass my .txt file over to use in the open()
# _*_ coding: utf-8 _*_
# Check if twitter usernames exist or are available
import argparse as ap
import requests
def args():
""" Get the arguments passed from the CLINE """
parser = ap.ArgumentParser()
parser.add_argument("u", help="The text file with all your usernames in")
return parser.parse_args()
def checker():
"""Loop through lines and check for available usernames"""
argslist = args()
usernames = open(argslist.u, "r")
lines = usernames.readlines()
usernames.close()
for line in lines:
url = "https://twitter.com/" + line
check = requests.get(url)
if check.status_code == 404:
print line + ' is avaialble'
else:
print line + ' is taken...'
checker()
Upvotes: 1
Views: 4593
Reputation: 47159
parser.add_argument
is incorrect for what you are putting as the argument.
C:\xampp\htdocs\py>twitter_checker.py -u C:\xampp\htdocs\py\test.txt
Should be using:
parser.add_argument("-u", help="The text file with all your usernames in")
Notice -u
instead of u
... switch one or the other (either the argument, or the parser).
Upvotes: 2