Example #1
0
def main():
    api = get_api()
    if not api:
        return
    try:
        locations = api.trend_locations()
    except tweetpony.APIError as err:
        print "Could not fetch the trend locations. Twitter returned error #%i and said: %s" % (
            err.code, err.description)
        return
    for location in locations:
        if location.placeType.code in [12,
                                       19]:  # Country (12) or Worldwide (19)
            print "%(woeid)i %(name)s" % location
        else:  # Town (7) or other place type
            print "%(woeid)i %(name)s, %(country)s" % location
    selected_id = raw_input(
        "Enter the number of the region you want to see the trends for: ")
    try:
        selected_trends = api.trends(id=selected_id)
    except tweetpony.APIError as err:
        print "Could not fetch the trends. Twitter returned error #%i and said: %s" % (
            err.code, err.description)
    else:
        print "\nHere are the trends!"
        print "=" * 25
        for trend in selected_trends:
            print trend.name
Example #2
0
    def main():
        factory = ChatterBotFactory()
        print 'hi'
        bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
        bot2session = bot2.create_session()

        api = get_api()
        if not api:
            return
        try:
            status = api.received_messages(count=1)
        except tweetpony.APIError as err:
            print "Oh no! Your tweet could not be sent. Twitter returned error #%i and said: %s" % (err.code, err.description)
        else:
           message_id=status[0]['id']
           user_id=status[0]['sender_screen_name']
        status = api.received_messages(since_id=message_id)
        while(1):
            if status:
                message_id=status[0]['id']
                user_id=status[0]['sender_screen_name']
                s = status[0]['text']
                if s=='Take':
                
                    s='You can download the image from the link - '+take_image();
                else:
                    s = bot2session.think(s);
                api.send_message(screen_name=user_id,text=s)
            time.sleep(60)
            status=api.received_messages(since_id=message_id)           
Example #3
0
def main():
    api = get_api()
    if not api:
        return
    try:
        locations = api.trend_locations()
    except tweetpony.APIError as err:
        print "Could not fetch the trend locations. Twitter returned error #%i and said: %s" % (
            err.code,
            err.description,
        )
        return
    for location in locations:
        if location.placeType.code in [12, 19]:  # Country (12) or Worldwide (19)
            print "%(woeid)i %(name)s" % location
        else:  # Town (7) or other place type
            print "%(woeid)i %(name)s, %(country)s" % location
    selected_id = raw_input("Enter the number of the region you want to see the trends for: ")
    try:
        selected_trends = api.trends(id=selected_id)
    except tweetpony.APIError as err:
        print "Could not fetch the trends. Twitter returned error #%i and said: %s" % (err.code, err.description)
    else:
        print "\nHere are the trends!"
        print "=" * 25
        for trend in selected_trends:
            print trend.name
Example #4
0
def main():
    api = get_api()
    if not api:
        return
    processor = StreamProcessor(api)
    try:
        api.user_stream(processor=processor)
    except KeyboardInterrupt:
        pass
Example #5
0
def main():
	api = get_api()
	if not api:
		return
	processor = StreamProcessor(api)
	try:
		api.user_stream(processor = processor)
	except KeyboardInterrupt:
		pass
Example #6
0
def main():
	api = get_api()
	if not api:
		return
	tweet = raw_input("Hello, %s! Compose a tweet: " % api.user.screen_name)
	try:
		status = api.update_status(status = tweet)
	except tweetpony.APIError as err:
		print "Oh no! Your tweet could not be sent. Twitter returned error #%i and said: %s" % (err.code, err.description)
	else:
		print "Yay! Your tweet has been sent! View it here: https://twitter.com/%s/status/%s" % (status.user.screen_name, status.id_str)
Example #7
0
def main():
	api = get_api()
	if not api:
		return
	username = raw_input("Username to lookup (leave blank for your own): ").strip()
	if username == "":
		username = api.user.screen_name
	try:
		user = api.get_user(screen_name = username)
	except tweetpony.APIError as err:
		print "Oh no! The user's profile could not be loaded. Twitter returned error #%i and said: %s" % (err.code, err.description)
	else:
		for key, value in user.iteritems():
			if key in ['entities', 'json', 'status']:
				continue
			line = "%s " % key.replace("_", " ").capitalize()
			line += "." * (50 - len(line)) + " "
			line += unicode(value)
			print line
def main():
    api = get_api()
    if not api:
        return
    username = input("Username to lookup (leave blank for your own): ").strip()
    if username == "":
        username = api.user.screen_name
    try:
        user = api.get_user(screen_name=username)
    except tweetpony.APIError as err:
        print(
            "Oh no! The user's profile could not be loaded. Twitter returned error #%i and said: %s"
            % (err.code, err.description))
    else:
        for key, value in user.items():
            if key in ['entities', 'json', 'status']:
                continue
            line = "%s " % key.replace("_", " ").capitalize()
            line += "." * (50 - len(line)) + " "
            line += str(value)
            print(line)
Example #9
0
	def on_message(self, message):
		print "Message received from @%s: %s" % (message.sender_screen_name, message.text)

		api = get_api()
		screen_name = "@" + message.sender_screen_name
		text = message.text + " (" + screen_name + ")"

		lines = [line.strip() for line in open(WHITELIST)]

		if any(screen_name in s for s in lines):
			print("User authorised")
			try:
    				api.update_status(status = text)
				print(text)
			except tweetpony.APIError as err:
			    print "Twitter returned error #%i and said: %s" % (err.code, err.description)
			else:
			    print "Tweet send"
		else:
			print("User not authorised")

		return True
Example #10
0
parser.add_argument("--google_locations", help="print out locations in google map friendy format", action="store_true");
parser.add_argument("--json", help="print out data in JSON", action="store_true");
parser.add_argument("--type", help="type of report to generate: incident, arrest, all");
parser.add_argument("--begin_date", help="start date to track");
parser.add_argument("--end_date", help="end date to track");
parser.add_argument("--tweet", help="tweet the results", action="store_true");
args = parser.parse_args()

print_google_locations = args.google_locations;
print_json = args.json;
print_type = args.type;
print_geocode = args.geocode;
tweet_results = args.tweet;

if( tweet_results ):
  api = get_api();
  if not api:
    exit

if( args.end_date ):
  now= datetime.datetime.strptime(args.end_date, "%m-%d-%Y");
  now  = datetime.datetime.strptime( now.isoformat(),"%Y-%m-%dT%H:%M:%S")
  now  = (str(now).split(" "))[0]
else:
  now = datetime.date.today();
	

if( args.begin_date ):
  then = datetime.datetime.strptime(args.begin_date, "%m-%d-%Y");
  then = datetime.datetime.strptime(then.isoformat(),"%Y-%m-%dT%H:%M:%S")
  then = (str(then).split(" "))[0]
Example #11
0
'04926422c52980' : ['2','Nina Simone: To Love Somebody',1,time_offset,'x-sonos-http:_t%3a%3a2995780.mp3?sid=11&flags=32'],
'04dd3a22c52980' : ['3','Bob Marley: One Cup of Coffee',0.8,time_offset,'x-sonos-http:_t%3a%3a39299573.mp3?sid=11&flags=32'],
'04b56322c52980' : ['4','Adele: Best for Last',0.8,'00:00:36','x-sonos-http:_t%3a%3a2893061.mp3?sid=11&flags=32'],
'04e46422c52980' : ['5','Jack Johnson: We are Going to Be Friends',0.8,time_offset,'x-sonos-http:_t%3a%3a2807102%3a%3aa%3a%3a231444.mp3?sid=11&flags=32'],
'048b6322c52980' : ['6','The Hollies: The Mighty Quinn',0.8,time_offset,'x-sonos-http:_t%3a%3a2568562.mp3?sid=11&flags=32'],
'04216522c52980' : ['7','Raffi: Baa Baa Black Sheep',1.15,time_offset,'x-sonos-http:_t%3a%3a5425710%3a%3aa%3a%3a441322.mp3?sid=11&flags=32'],
'04df3a22c52980' : ['8','K\'naan: In the Beginning',0.75,'00:00:13','x-sonos-http:_t%3a%3a5407313.mp3?sid=11&flags=32'],
'04cb6422c52980' : ['9','Tuck & Patti: Honey Pie',1.3,'00:00:41','x-sonos-http:_t%3a%3a3053744.mp3?sid=11&flags=32'],
'04436422c52980' : ['10','Miriam Makeba: Pata Pata',0.9,'00:00:09','x-sonos-http:_t%3a%3a1163595.mp3?sid=11&flags=32'],
'049e6422c52980' : ['11','Yo-Yo Ma & Bobby McFerrin: Flight of the Bumblebee',1.2,time_offset,'x-sonos-http:_t%3a%3a8805968.mp3?sid=11&flags=32'],
'04536422c52980' : ['12','Desmond De Silva: Babi Achchee',0.8,time_offset,'x-sonos-http:_t%3a%3a43013728.mp3?sid=11&flags=32'],
}

# Twitter setup
print("Connecting to Twitter...")
twitter_api = get_api()
if twitter_api:
    print ("Connected to Twitter")
else:
    print ("Twitter connection error")
print ("")


# Sonos setup
print("Connecting to Sonos...")
sonos = SoCo(sonos_ip)
print ("Connected to Sonos: " + sonos.player_name)

# Use this section to get the URIs of new songs we want to add
info = sonos.get_current_track_info()
print("Currently Playing: " + info['title'])
Example #12
0
        '10', 'Miriam Makeba: Pata Pata', 0.9, '00:00:09',
        'x-sonos-http:_t%3a%3a1163595.mp3?sid=11&flags=32'
    ],
    '049e6422c52980': [
        '11', 'Yo-Yo Ma & Bobby McFerrin: Flight of the Bumblebee', 1.2,
        time_offset, 'x-sonos-http:_t%3a%3a8805968.mp3?sid=11&flags=32'
    ],
    '04536422c52980': [
        '12', 'Desmond De Silva: Babi Achchee', 0.8, time_offset,
        'x-sonos-http:_t%3a%3a43013728.mp3?sid=11&flags=32'
    ],
}

# Twitter setup
print("Connecting to Twitter...")
twitter_api = get_api()
if twitter_api:
    print("Connected to Twitter")
else:
    print("Twitter connection error")
print("")

# Sonos setup
print("Connecting to Sonos...")
sonos = SoCo(sonos_ip)
print("Connected to Sonos: " + sonos.player_name)

# Use this section to get the URIs of new songs we want to add
info = sonos.get_current_track_info()
print("Currently Playing: " + info['title'])
print("URI: " + info['uri'])