def profile_picture_for_account(username):
    all_accounts = twitter.get_all_accounts()
    if len(all_accounts) >= 1:
        account = all_accounts[0]
        parameters = {'screen_name': username}
        status, data = twitter.request(
            account, 'https://api.twitter.com/1.1/users/show.json', 'GET',
            parameters)
        if status == 200:
            user_info = json.loads(data)
            avatar_url = user_info['profile_image_url']
            # Get the URL for the original size:
            avatar_url = avatar_url.replace('_normal', '')
            filename, headers = urllib.request.urlretrieve(avatar_url)
            img = Image.open(filename)
            format = img.format.lower()
            path = os.path.expanduser('~/Documents/{}.{}'.format(
                username, format))
            img.save(path, format=format)
            image = ui.Image.named(path)
            os.remove(path)
            return image
        else:
            raise LoadTwitterProfilePictureError(status)
    else:
        raise NoTwitterAccountSetUpError(
            'You don\'t have any Twitter accounts (or haven\'t given permission to access them).'
        )
def main():
	all_accounts = twitter.get_all_accounts()
	if len(all_accounts) >= 1:
		account = all_accounts[0]
		twitter.post_tweet(account, textview.text)
		console.hud_alert('ツイートしました。')
		
	else:
		console.hud_alert('Twitterアカウントが登録されていません。','error')
示例#3
0
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)
示例#4
0
def tweet(text):
    all_accounts = twitter.get_all_accounts()
    if len(all_accounts) >= 1:
        account = all_accounts[0]  # get main account
        text = dialogs.text_dialog(
            text=text, autocapitalization=ui.AUTOCAPITALIZE_SENTENCES)
        if text:
            twitter.post_tweet(account, text, parameters=None)
            console.hud_alert('Tweet Posted!', 'success', 1.5)
        else:
            console.hud_alert('Canceled', 'error', 1.5)
示例#5
0
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
def post_twitter(desc, url):
  # Post description + url
  all_accounts = twitter.get_all_accounts()
  if len(all_accounts) >= 1:
    account = all_accounts[0]
    parameters = {'screen_name': account['username']}
    status, data = twitter.request(account, 'https://api.twitter.com/1.1/users/show.json', 'GET', parameters)
  
  # Trim description to tweetable size 
  # 140 Total - 22 bit.ly URL = 118
  
  shortdesc = (desc[:116] + '..') if len(desc) > 118 else data
  
  twitter.post_tweet(account, shortdesc +" "+ url)
  print('\n(2) Twitter Post Successful \n')
示例#7
0
def post_twitter(desc, url):
    # Post description + url
    all_accounts = twitter.get_all_accounts()
    if len(all_accounts) >= 1:
        account = all_accounts[0]
        parameters = {'screen_name': account['username']}
        status, data = twitter.request(
            account, 'https://api.twitter.com/1.1/users/show.json', 'GET',
            parameters)

    # Trim description to tweetable size
    # 140 Total - 22 bit.ly URL = 118

    shortdesc = (desc[:116] + '..') if len(desc) > 118 else data

    twitter.post_tweet(account, shortdesc + " " + url)
    print('\n(2) Twitter Post Successful \n')
def profile_picture_for_account(username):
	all_accounts = twitter.get_all_accounts()
	if len(all_accounts) >= 1:
		account = all_accounts[0]
		parameters = {'screen_name': username}
		status, data = twitter.request(account, 'https://api.twitter.com/1.1/users/show.json', 'GET', parameters)
		if status == 200:
			user_info = json.loads(data)
			avatar_url = user_info['profile_image_url']
			# Get the URL for the original size:
			avatar_url = avatar_url.replace('_normal', '')
			filename, headers = urllib.urlretrieve(avatar_url)
			img = Image.open(filename)
			format = img.format.lower()
			path = os.path.expanduser('~/Documents/{}.{}'.format(username, format))
			img.save(path, format=format)
			image = ui.Image.named(path)
			os.remove(path)
			return image
		else:
			raise LoadTwitterProfilePictureError(status)
	else:
		raise NoTwitterAccountSetUpError('You don\'t have any Twitter accounts (or haven\'t given permission to access them).')
示例#9
0
# coding: utf-8

# See: https://forum.omz-software.com/topic/2794/old-bugs/19

import twitter

account = twitter.get_all_accounts()[0]
fmt = """> user: {user[screen_name]}
{text}
________________________>"""


def perform_search():
    data = twitter.search(account,
                          "Privacy OR Apple from:RepTedLieu",
                          parameters={"result_type": "mixed"})
    print("\n".join(fmt.format(**status) for status in data["statuses"]))


perform_search()
import twitter, ui, dialogs, console
all_accounts = twitter.get_all_accounts()
if len(all_accounts) >= 1:
	account = all_accounts[0] # get main account
text = dialogs.text_dialog(title='Tweet a Tweet', autocapitalization=ui.AUTOCAPITALIZE_SENTENCES)
if len(text) < 140:
		twitter.post_tweet(account, text, parameters=None)
		console.hud_alert('Tweet Posted!', 'success', 1.5)
else:
		console.hud_alert('Exceeded Character Limit', 'error', 1.5)
示例#11
0
def get_first_twitter_account():
    try:
        return twitter.get_all_accounts()[0]
    except IndexError:
        console.hud_alert(twitter_err, 'error', 3)
        return None