My Python script doesn't give me an error or shows any output

1.2k Views Asked by At

I'm creating a simple transit twitter-bot which posts a tweet to my API, then grabs the result to later on reply with an answer on travel times and such. All the magic is on the server-side , and this code should work just fine. Here's how:

A user composes like the tweet below:

@kollektiven Sundsvall Navet - Ljustadalen

My script removes the @kollektiven from the tweet, send the rest Sundsvall Navet - Ljustadalen to our API. Then a JSON should be given to the script. The script should later on reply you with an answer like this:

@jackbillstrom Sundsvall busstation Navet (2014-01-08 20:45) till Ljustadalen centrum (Sundsvall kn) (2014-01-08 20:59)

But it doesn't. I'm using this code from github called spritzbot. I edited the extensions/hello.py to look like the one below:

# -*- coding: utf-8 -*-

import json, urllib2, os

os.system("clear")

def process_mention(status, settings):
    print status.user.screen_name,':', status.text.encode('utf-8')
    urlencode = status.text.lower().replace(" ","%20") # URL-encoding
    tweet = urlencode.strip('@kollektiven ')
    try:
        call = "http://xn--datorkraftfrvrlden-xtb17a.se/kollektiven/proxy.php?input="+tweet # Endpoint
        endpoint = urllib2.urlopen(call) # GET-Request to API endpoint
        data = json.load(endpoint) # Load JSON
        answer = data['proxyOutput'] # The answer from the API
        return dict(response=str(answer)) # Posts answer tweet 

    except:
        return dict(response="Error, kontakta @jackbillstrom") # Error-meddelande

What is causing this problem? And why? I made some changes before I came to this revision, and it worked back then.

2

There are 2 best solutions below

1
On BEST ANSWER

You need:

if __name__ == '__main__':
    process_mention(...)
    ...
2
On

You're not calling process_mention anywhere, just defining it.