Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python Tweepy Code Issue

Im endeavouring to capture some twitter data for a college assignment, specifically tweets with #construction, using Tweepy in Python / Terminal on Mac. Im looking to pull tweets posted in the last 7 days. The code I've been trying to use is as per below but its returning the following error:

Error lifted from Terminal command line:

SyntaxError: unterminated string literal (detected at line 1)


Code i'm trying to use:

Python:
import tweepy
import datetime

access_token="access token here"
access_token_secret="access token secret here"
consumer_key="consumer key here"
consumer_secret="consumer secret here"
auth= tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)

api = tweepy.API(auth,wait_on_rate_limit=True)

today = datetime.date.today()
yesterday= today - datetime.timedelta(days=7)
today, yesterday

tweets_list = tweepy.Cursor(tweepy.api.search, q="#23construction:" + str(yesterday)+ "
until:" + str(today),tweet_mode='extended', lang='it').items()


Any ideas why this isn't performing as desired? Thanks in advance.
 
Last edited by a moderator:
I'm not a Python expert and have no idea what this is trying to do, but it looks like you are breaking the last statement in the middle of a string - not a good idea in any language. Not sure why the error mentions line 1 ... but I don't see an unterminated string literal elsewhere.
 
Does this work?

Python:
mport tweepy
import datetime

access_token="access token here"
access_token_secret="access token secret here"
consumer_key="consumer key here"
consumer_secret="consumer secret here"
auth= tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)

api = tweepy.API(auth,wait_on_rate_limit=True)

today = datetime.date.today()
yesterday= today - datetime.timedelta(days=7)
today, yesterday

tweets_list = tweepy.Cursor(tweepy.api.search, q="#23construction:" + str(yesterday)+ "until:" + str(today),tweet_mode='extended', lang='it').items()
 
Does this work?

Python:
mport tweepy
import datetime

access_token="access token here"
access_token_secret="access token secret here"
consumer_key="consumer key here"
consumer_secret="consumer secret here"
auth= tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)

api = tweepy.API(auth,wait_on_rate_limit=True)

today = datetime.date.today()
yesterday= today - datetime.timedelta(days=7)
today, yesterday

tweets_list = tweepy.Cursor(tweepy.api.search, q="#23construction:" + str(yesterday)+ "until:" + str(today),tweet_mode='extended', lang='it').items()
So its not throwing up the same error which is great. Once executed on the command line it's presenting me with three dots, almost like its expecting more code to follow. Any thoughts?
 
So its not throwing up the same error which is great. Once executed on the command line it's presenting me with three dots, almost like its expecting more code to follow. Any thoughts?
I'm not sure, and I don't think anyone here specialises in the Tweepy Python module. Try posting this question on Stack Overflow, where there may be people more suited to help you.
 
I'm surprised this is not throwing a new error now due to the missing i at the beginning 😉
But if you're surprised at the three dots : what did you expect to happen ? You are not outputting anything, and not giving the interpreter any indication that it has reached the end of code. I think you need to terminate the code block with a stop or end or exit or whatever, otherwise it just sits there waiting for the next line. I could be all wrong but it does seem likely.
 
I'm surprised this is not throwing a new error now due to the missing i at the beginning 😉
But if you're surprised at the three dots : what did you expect to happen ? You are not outputting anything, and not giving the interpreter any indication that it has reached the end of code. I think you need to terminate the code block with a stop or end or exit or whatever, otherwise it just sits there waiting for the next line. I could be all wrong but it does seem likely.
I think they just forgot to put the 'i' in the code tag.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom