ptwobrussell / Mining-the-Social-Web

The official online compendium for Mining the Social Web (O'Reilly, 2011)
http://bit.ly/135dHfs
Other
1.21k stars 491 forks source link

linkedin__analyze_titles.py #51

Closed vivdx closed 11 years ago

vivdx commented 11 years ago

Traceback (most recent call last): File "C:/Users/Desktop/linkedin_analyze_titles.py", line 6, in CSV_FILE = sys.argv[1] IndexError: list index out of range

and when I fix this error with sys.argv[0]

File "C:/Users/Desktop/linkedin_analyze_titles.py", line 30, in titles.extend([t.strip() for t in contact['Job Title'].split('/') KeyError: 'Job Title'

vivdx commented 11 years ago

and also could we skip oauthDance in linkedin_get_connections.py

Are there some changes as of new API ? correct me if I am wrong.

vivdx commented 11 years ago

linkedin_geocode.py

K = int(sys.argv[0]) ValueError: invalid literal for int() with base 10:

i am using Active Python 2.7 (64bit)

ptwobrussell commented 11 years ago

Not totally sure what you mean by when you "fix" the IndexErrors? The script is designed to accept command line parameters, but you could just as easily hardcode in absolute or relative paths. Is that what you mean?

I don't think you can skip the way the OAuth dance works for LinkedIn in the same way that you can with some of the other social web properties like Twitter or Facebook, which give you access tokens to work with.

In terms of API changes, yes, there have been some that have happened since the book was written, although I've tried to keep it up to date the best I can based on feedback from readers. One thing that you might find useful is the code repository for the 2nd Edition of Mining the Social Web, which is available at https://github.com/ptwobrussell/Mining-the-Social-Web-2nd-Edition - right now, 5 of the chapters are checked in as IPython Notebooks, including the chapter on LinkedIn, which you may find useful. It's all fully up to date and very recently tested through and through. The text for the 2nd Edition is also available as an Early Release ebook from O'Reilly. All in all, I think the 2nd Edition code (and book) is superior to the 1st edition in just about every way, so I'd highly recommend it.

But as far as I know, this code for the 1st edition should still be in good working order. One thing I can tell you though is that in order for the https://github.com/ptwobrussell/Mining-the-Social-Web/blob/master/python_code/linkedin__geocode.py script to work, you'll want to use Bing as the provider. From what I could tell while revising this code for the 2nd Edition, both Yahoo! and Google Maps no longer worked properly with the geopy library that is used to get the heavy lifting done. The IPython Notebook for LinkedIn for the 2nd Edition should be a good way to illustrate a nice workflow that accomplishes the same goal, although I will dedicate some time to revisiting/testing https://github.com/ptwobrussell/Mining-the-Social-Web/blob/master/python_code/linkedin__geocode.py over the weekend if you believe that you are having problem with it.

I'm not sure about the line of code K = int(sys.argv[0]) that you posted above, because the script that's checked in shows that you should be capturing the sys.argv[1] argument. In Python, the 0 argument is the name of the script with 1..N being the arguments that are the parameters you pass to the script.

vivdx commented 11 years ago

Thanks for such a descriptive reply. For Linkedin , linkedin developer is providing us OAuth User Token & OAuth User Secret linkedin_token

vivdx commented 11 years ago

And I was using sys.argv[1] but it gives the same error : ValueError: invalid literal for int()

maybe I am making some mistakes ...

ptwobrussell commented 11 years ago

The particular ValueError you're getting makes me think that you're passing in some value that is not a number as that first argument. How are you invoking the script in the terminal? Can you show me your full command you are using to run the script? I might be able to help you more if I knew what parameters you were passing.

vivdx commented 11 years ago

I am using Python Shell (Active Python 2.7) to invoke the script. I am jsut pressing f5 to execute it. I have used it with other scripts it works fine.

vivdx commented 11 years ago

value error

ptwobrussell commented 11 years ago

Okay, I understand what you are trying to do, and the problem is that the script requires arguments to be passed in to it, so you do have to supply those values somehow - either through a setting in your Python GUI you are using or by modifying the source code to not use sys.argv at all and instead hard coding in parameters directly. For example, in a terminal, you could run the script like

$ python linkedin__geocode.py 4 YOUR_API_KEY PATH_TO_YOUR_DATA_FILE

Can you show me what those parameters are that you're passing in through your Active Python shell? My guess is that the first parameter is not a number. For example, if I run this script:

import sys
print sys.argv[1]

and if I invoke it by passing in a string as the parameter such as:

$ python foo.py aaa

Then I get the same kind of ValueError that you are reporting.

ptwobrussell commented 11 years ago

I believe that we started to narrow this issue down to being something related to the way that you were running the script versus anything in particular with the script being wrong? I'll go ahead and close this ticket since I haven't heard back otherwise, but please do reopen it if you think this is my error and that we still need to work it out. Thank you!