An overview of the approach I took

For the last month or so, I've been sharing what I'm working on, in the weekly hacker-coder thread that appearsin /r/india every Friday. Last week, I went over to the Python subreddit to share what I've been working on.

A redditor messaged me saying

Hey, i just saw your comment on this thread and i really liked your idea. So im going to try to do it myself (also a bit of a beginner like you) for fun and to learn a little more.
Can you show some of the websites you used for reference while creating your script, please?
And if you were to give me your source code so that I can see how is it made it would be amazing (thought i understand if you refuse to this last request).
And one last question: I suspect i know even less about programming than you so is this script very hard?
Thank you!!


I figured I'd post the reply I sent over here so that it might help another Python beginner get his feet wet.




Sure, happy to point you in the right direction.
I started off with this script. It was a weekend project in which Andrej Karpathy wrote a Python script which would recommend twitter followers for you. The source of signal is that the people you follow follow other people you probably should follow but so far do not. Basically, like how Facebook recommends people based on your mutual friends.
The process of installing is decently documented so I would suggest you get that script up and running first, as I did.
I first spent time understanding that code. Took me a while (don't lose motivation if it takes you a while as well, it's entirely normal because although the script that fetches the data is only 2 'small' files. It has a lot of newconcepts that need to be understood if you're new like I was.)
  • Argparse (passing arguments to python scripts)
  • Pickle
  • Using the OS module
  • Logging
  • Lists/Dictionary sorting/traversal
There weren't specific websites that I used as references. I just googled each keyword and tried to understand what they did, then tried to independently implement those concepts of the code in another file to understand how they fit into the main script. Small victories.
I suspect i know even less about programming than you so is this script very hard?
Don't worry about that. I probably never would've started on this project if I thought it was tough. The only thing that kept me going was that it was literally 2 small files of code, surely I could understand it. It's entirely possible.

I wouldn't mind sharing the code of the location-finding script with you but it's hugely derivative of this script. You should try to implement it after you understand this code, if I share the script and you read it, you'll be deprived of the understanding. It's the journey that matters!
After I understood the above code, I used the googlemaps module to use its Geocoding API.

While I was going step by step through fetch.py, I made some extra comments to understand the code. You can find them here.
Hope you find them helpful.
The other code samples are .. examples of the short independent pieces that I tried to run in a new file to understand them before I could understand how they fit into the main jigsaw. You should try to run them and create your own small subfiles to understand it better.