Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess global queue object in python
    primarykey
    data
    text
    <p>I am building a messaging app in python that interfaces with twitter I want to create a global fifo queue that the twitterConnection object can access to insert new messages.</p> <p>this is the main section of the app:</p> <pre><code> #!/usr/bin/python from twitterConnector import TwitterConnector from Queue import deque #instantiate the request queue requestQueue = deque() #instantiate the twitter connector twitterInterface = TwitterConnector() #Get all new mentions twitterInterface.GetMentions() </code></pre> <p>Specifically I want to be able to call the .GetMentions() method of the TwitterConnector class and process any new mentions and put those messages into the queue for processing separately.</p> <p>This is the twitterConnector class so far:</p> <pre><code>class TwitterConnector: def __init__(self): self.connection = twitter.Api(consumer_key=self.consumer_key,consumer_secret=self.consumer_secret,access_token_key=self.access_token_key,access_token_secret=self.access_token_secret) self.mentions_since_id = None def VerifyCredentials(self): print self.connection.VerifyCredentials() def GetMentions(self): mentions = self.connection.GetMentions(since_id=self.mentions_since_id) for mention in mentions: print mention.text global requestQueue.add(mention) # &lt;- error </code></pre> <p>Any assistance would be greatly appreciated.</p> <p>Update: let me see if I can clarify the use case a bit. My TwitterConnector is intended to retrieve messages and will eventually transform the twitter status object into a simplified object that contains the needed information for downstream processing. In the same method, it will perform some other calculations to try to determine other needed information. It is actually the transformed objects that I want to put into the queue. hopefully that makes sense. As a simplified example, this method would map the twitter status object to a new object that would contain properties such as: origin network (twitter), username, message, and location if available. This new object would then be put into the queue.</p> <p>eventually there will be other connectors for other messaging systems that will perform similar actions. They will receive a message populate the new message object and place them into the same queue for further processing. Once the message has been completely processed a response would be formulated and then added to an appropriate queue for transmittal. Using the new object described above the once the actual processing of the tweet content took place then based upon the origin network and username a response might be returned to the originator via twitter.</p> <p>I had thought of passing a reference to the queue in the contractor (or as an argument to the method) I had also thought of modifying the method to return a list of the new objects and iterate over them to put them into the queue, but I wanted to make sure there wasn't a better or more efficient way to handle this. I also wish to be able to do the same thing with a logging object and a database handler. Thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload