Forum Archive

Tweet.py example

richexperiences

Hello - brand new to Python. I’m trying to test the Tweet.py example. I’ve add my twitter handle but still get an error. This script doen’t need any active twitter account on my iOS device setup does it? I mean, I do have one, but it shouldn’t matter, right?

# coding: utf-8
import twitter

def main():
    accounts = twitter.get_all_accounts()
    if not accounts:
        print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.')
    account = accounts[0]
    username = account['richexperiences']
    print('Loading recent tweets in %s\'s timeline...' % (username,))
    tweets = twitter.get_home_timeline(account)
    for tweet in tweets:
        print('%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text']))
        print('-' * 40)

if __name__ == '__main__':
    main()
Drizzel

If the code in tweet.py is exactly the same as what you showed us, you’re missing a # before the coding: utf-8. Corrected, you would have to change your first line to

#coding: utf-8

The # is commonly used for commenting your code in normal language, as it tells the python interpreter that the following line is no actual python code and can therefore be ignored. The interpreter makes your code understandable for machines and therefore executable also.

If you want to know more or this is not the correct answer, just ask again and again and again 😋

Drizzel

Oh, and your last two lines should be:

if __name__ == '__main__':
    main()

This should be a working version:

# coding: utf-8
import twitter

def main():
    accounts = twitter.get_all_accounts()
    if not accounts:
        print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.')
    account = accounts[0]
    username = account['username']
    print('Loading recent tweets in %s\'s timeline...' % (username,))
    tweets = twitter.get_home_timeline(account)
    for tweet in tweets:
        print('%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text']))
        print('-' * 40)

if __name__ == '__main__':
    main()
ltddev

@Drizzel, I am looking at your replies over and over again and feel I must be missing something. In both replies you suggest changing code to what @richexperiences has actually already presented.

It seems to me that in both cases the code ALREADY states what you are suggesting it should be changed to,

@Drizzel, could you please clarify what the differences are between the code as already written and the code you suggest it be changed to?

cvp

@ltddev Now the code of the first post seems to be exactly the same as @Drizzel one but the first time we saw the first post, the script was not inside the three back quotes pair, and the # of the first line and underscores of main line were not visible...

mikael

@richexperiences, what is the error?

The code itself says:

print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.')

So you do need to have a Twitter account configured on the device, and you need to have approved access to the account.

dgelessus

The twitter module no longer works on recent iOS versions, because iOS no longer has any special native support for Twitter. Quoting the in-app docs for the twitter module:

Warning: Unfortunately, this module no longer works on iOS 11 and later because the underlying APIs have been removed from iOS.

ltddev

@dgelessus - are you saying flat out that as of IOS 11 there is no way to get Pythonista (or any other IOS app ) to talk to Twitter? Since there is no native apis, there can be no straightforward way tor any IOS app ( other than presumably the Twitter app itself) to code ro Twitter?

mikael

@ltddev, Twitter provides an online (URL-based) API, and there are several Python implementations for using it (see here for the first nine). Since there is no obvious reason for them to include C components, most of them will probably work with Pythonista. To give them a try, it is best to first install stash, if you have not yet done so.

frahia

After grilling out with propane for many years I purchased a pellet grill Friday. I first grilled some steaks. Yesterday I smoked a rack of ribs. Today it was burgers and stuffed peppers. Pellet cooking is all new to me but I'm loving it so far. I started this thread in hopes we might share some kick butt recipes and cooking tips. Talk about the best grills or at least the best for the bucks. The problems we've experienced grilling and the crazy/funny grilling stories ... you name it.. all things grillin.

This is my new grill. It uses wood pellets as fuel. They can be had in natural flavors such as hickory, mesquite, cherry, apple, alder, etc.
They are fed into a burn pot by an auger that is controlled by a thermostat. There is a fan inside that spreads the heat such as a convection oven. The concept is not new but it was new to me a couple of years ago. I've had the desire for one since and took the leap Friday..front
My grill came without a cookbook so I'm winging it.