-3

I am kinda new to working with json and python and I am stuck on the parsing the data in js to generate an expression. I would really appreciate anyone suggestions on the best path to take.

Here is the Data I am working with

{"statuses":[{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Fri Dec 06 15:06:44 +0000 2013","id":408975801577926656,"id_str":"408975801577926656","text":"RT @jk636575: @GhanaNudes contact me if you want to swing\njk636575@gmail.com","user":{"id":974873810,"id_str":"974873810","name":"Gh Nudes","screen_name":"GhanaNudes","location"

Here is my code:

def main():
    ts = TwitterSearch()
    response, data = ts.search('@gmail.com', result_type='recent')
    js = json.loads(data)

    messages = ([data_items] for msg in js)

I need to parse the content in js and turn it into a generator expression so that I only write: Created_at , text , user:{is

user2748540
  • 209
  • 1
  • 3
  • 12
  • 1
    What does your current code do? How is that wrong? What do you want it to do? This question is unclear at best. – Gareth Latty Dec 06 '13 at 15:20
  • 3
    I can answer, but.. Won't. Help. You. Searching. For. Porn. – aIKid Dec 06 '13 at 15:29
  • He is trying to complete my answer to http://stackoverflow.com/questions/20414701/twitter-python-json-to-csv/20415034?noredirect=1#comment30493467_20415034 – Hugh Bothwell Dec 06 '13 at 15:29
  • 1
    yes, i am not trying to look for porn but that particular piece of the data is quite funny. I am actually trying to locate people who mention their email address in a public forum and associate it to a twitter ID – user2748540 Dec 06 '13 at 17:33
  • Yes it is to complete the question Hugh helped with prior in the evening stackoverflow.com/questions/20414701/twitter-python-json-to-csv/… – user2748540 Dec 06 '13 at 17:34
  • @user2748540 Just read that. Loled. That's rather unfortunate. – aIKid Dec 10 '13 at 13:42

1 Answers1

0

Based on the Twitter search API docs,

messages = ([msg['created_at'], msg['txt'], msg['user']['id']] for msg in js['statuses'])

Note that I have updated my answer to the original question to include this.

Edit: It might be a bit safer to replace in js['statuses'] with in js.get('statuses', []).

Community
  • 1
  • 1
Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99