Skip to content

Instantly share code, notes, and snippets.

@SkamDart SkamDart/ forked from jimmc2/
Last active Jan 8, 2018

What would you like to do?
## Import libraries and functions needed
## define URL
def get_url(All=None, Exact=None, Any=None, Not=None, Hashtag=None, From=None,
To=None, Mention=None, Near=None, Dates=None):
#Base URL
url = ""
# All
if All != None:
a = All.replace(" ", "%20")
url = url + a
if Exact != None:
b = Exact.replace(" ", "%20")
url = url + "%22" + b + "%22"
if Any != None:
c = Any.replace(" ", "%20OR%20")
url = url + "%22" + c + "%22"
if Not != None:
d = Not.replace(" ", "%20-")
url = url + "%20-" + d
if Hashtag != None:
e = Hashtag.replace(" ", "%20OR%20%23")
url = url + "%23" + e
if Hashtag != None:
f = Hashtag.replace(" ", "%20OR%20%23")
url = url + "%23" + f
#Base URL end
url = url + "&src=typd"
## Scrape URL
def create_url(*args, **kwargs):
*args is an array of arguments ignore this for right now
**kwargs is dictionary "key-value" mapping of keywords and their arguments
in this case, you can pass any arbitrary amount of named arguments to your parameters
and iterate through them. I'll explain this a little more when I start writing code
if you called, create_url(near="im", dates="jim")
this for loop would print
near -> im
dates -> jim
for key, value in kwargs.items():
# here is where you add the checks that you have above!
# for right now i'm just printing the key and it's value!
# this is also just a fancy way to print things nicely
# every {} in the string is replaced with the parameter in the format argument
print("{} -> {}".format(key, value))
If you run `python` this function below is what python looks for and executes
if __name__ == '__main__':
Look at what my code says and see if you can figure out what the commented out
function calls will print
Then uncomment and see if you were right
# create_url(im='jim')
see what you can do now is
# create_url(hashtag="mydude")
a little more advanced would be to make it so you can call this from the command line
python boner soup
for arg in argv:
from sys import argv
# create an empty dictionary
tags = {}
# iterate through all
for arg in argv[1:]:
# assumes input looks like
# name=cam
# splits a string into a name and a value by the single equals sign
name, value = arg.split("=", 1)
# creates a dictionary with single item
tag = {
name: value
# adds that tag to the rest of our tags
python any=yes from=2017 to=2018
(I just made up that call so don't blame me if it doesn' twork)
# Create csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.