From d684abd9f579afd8540b817a438e54a5e7645470 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 12 Feb 2020 22:37:26 -0800 Subject: [PATCH 01/23] Week 1 Labs * Visualizing Company Tweets * Visualizing Celebrity Tweets --- .../Visualizing Tweets - Celebrities/1.md | 14 ++++++++ .../Visualizing Tweets - Celebrities/11.md | 24 +++++++++++++ .../Visualizing Tweets - Celebrities/111.md | 36 +++++++++++++++++++ .../Visualizing Tweets - Celebrities/12.md | 7 ++++ .../Visualizing Tweets - Celebrities/121.md | 6 ++++ .../Visualizing Tweets - Celebrities/122.md | 17 +++++++++ .../Visualizing Tweets - Celebrities/2.md | 8 +++++ .../Visualizing Tweets - Celebrities/21.md | 7 ++++ .../Visualizing Tweets - Celebrities/211.md | 20 +++++++++++ .../Visualizing Tweets - Celebrities/212.md | 8 +++++ .../Visualizing Tweets - Celebrities/3.md | 9 +++++ .../Visualizing Tweets - Celebrities/31.md | 4 +++ .../Visualizing Tweets - Celebrities/311.md | 21 +++++++++++ .../Visualizing Tweets - Celebrities/32.md | 9 +++++ .../Visualizing Tweets - Celebrities/321.md | 3 ++ .../Visualizing Tweets - Celebrities/322.md | 18 ++++++++++ .../Visualizing Tweets - Celebrities/4.md | 12 +++++++ .../Visualizing Tweets - Celebrities/41.md | 3 ++ .../Visualizing Tweets - Celebrities/411.md | 16 +++++++++ .../Visualizing Tweets - Celebrities/412.md | 14 ++++++++ .../Visualizing Tweets - Celebrities/42.md | 3 ++ .../Visualizing Tweets - Celebrities/421.md | 9 +++++ .../Visualizing Tweets - Celebrities/5.md | 3 ++ .../Visualizing Tweets - Celebrities/51.md | 4 +++ .../Visualizing Tweets - Celebrities/511.md | 9 +++++ .../Visualizing Tweets - Celebrities/52.md | 7 ++++ .../Visualizing Tweets - Celebrities/521.md | 16 +++++++++ .../Visualizing Tweets - Celebrities/522.md | 21 +++++++++++ .../Visualizing Tweets - Celebrities/53.md | 10 ++++++ .../Visualizing Tweets - Celebrities/531.md | 22 ++++++++++++ .../Visualizing Tweets - Celebrities/54.md | 3 ++ .../Visualizing Tweets - Celebrities/541.md | 28 +++++++++++++++ .../Visualizing Tweets - Companies/1.md | 12 +++++++ .../Visualizing Tweets - Companies/11.md | 24 +++++++++++++ .../Visualizing Tweets - Companies/111.md | 36 +++++++++++++++++++ .../Visualizing Tweets - Companies/12.md | 7 ++++ .../Visualizing Tweets - Companies/121.md | 6 ++++ .../Visualizing Tweets - Companies/122.md | 17 +++++++++ .../Visualizing Tweets - Companies/2.md | 8 +++++ .../Visualizing Tweets - Companies/21.md | 7 ++++ .../Visualizing Tweets - Companies/211.md | 20 +++++++++++ .../Visualizing Tweets - Companies/212.md | 8 +++++ .../Visualizing Tweets - Companies/3.md | 9 +++++ .../Visualizing Tweets - Companies/31.md | 4 +++ .../Visualizing Tweets - Companies/311.md | 21 +++++++++++ .../Visualizing Tweets - Companies/32.md | 9 +++++ .../Visualizing Tweets - Companies/321.md | 3 ++ .../Visualizing Tweets - Companies/322.md | 18 ++++++++++ .../Visualizing Tweets - Companies/4.md | 12 +++++++ .../Visualizing Tweets - Companies/41.md | 3 ++ .../Visualizing Tweets - Companies/411.md | 16 +++++++++ .../Visualizing Tweets - Companies/412.md | 14 ++++++++ .../Visualizing Tweets - Companies/42.md | 3 ++ .../Visualizing Tweets - Companies/421.md | 9 +++++ .../Visualizing Tweets - Companies/5.md | 3 ++ .../Visualizing Tweets - Companies/51.md | 4 +++ .../Visualizing Tweets - Companies/511.md | 9 +++++ .../Visualizing Tweets - Companies/52.md | 7 ++++ .../Visualizing Tweets - Companies/521.md | 16 +++++++++ .../Visualizing Tweets - Companies/522.md | 21 +++++++++++ .../Visualizing Tweets - Companies/53.md | 10 ++++++ .../Visualizing Tweets - Companies/531.md | 22 ++++++++++++ .../Visualizing Tweets - Companies/54.md | 3 ++ .../Visualizing Tweets - Companies/541.md | 28 +++++++++++++++ 64 files changed, 780 insertions(+) create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/11.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/111.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/12.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/121.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/122.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/2.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/21.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/211.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/212.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/3.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/31.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/311.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/32.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/321.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/322.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/4.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/41.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/411.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/412.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/42.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/421.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/5.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/51.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/511.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/52.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/521.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/522.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/53.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/531.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/54.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/541.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/11.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/111.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/12.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/121.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/122.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/2.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/21.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/211.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/212.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/3.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/31.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/311.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/32.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/321.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/322.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/4.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/41.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/411.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/412.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/42.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/421.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/5.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/51.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/511.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/52.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/521.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/522.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/53.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/531.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/54.md create mode 100644 Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/541.md diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md new file mode 100644 index 00000000..45e44817 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md @@ -0,0 +1,14 @@ + + +For this lab, we will be analyzing tweets using Twitter's API and `tweepy` package in Python by creating a Word Cloud to observe the frequency of words being used in a celebrity's tweets. + +Analyzing the words used by a celebrity in an increasingly cluttered social media world has many uses. + +In this day and age, having a prominent social media presence can mean the difference for celebrities' public persona. A celebrity can use social media to generate excitement from millions of fans on Twitter, and if done right, propel their fame to new heights. Conversely, celebrities have to be careful about what they post on a site like Twitter, because one offensive tweet will get viral for the wrong reasons and destroy their reputation, not just in social media but in real life as well. Therefore, the words that celebrities choose when tweeting are vitally important, to cultivate an online persona and propel their own fame. Seeing the most common words in their tweets can help us find common trends in their tweets and determine what kind of persona they wish to conjure on social media. + +To do this in Python using `tweepy`, you should start off by importing our necessary libraries. The libraries we will be using are: + +`tweepy`, `pandas`, `sys`, `csv`, `WordCloud` and `STOPWORDS` from `wordcloud`, `matplotlib`, `matplotlib.pyplot`, `string`, `re`, `PIL` + +The next thing we want is to be able to use the python-twitter API client. To do that, you need to acquire a declare a set of application tokens. Name the tokens `consumer_key`, `consumer_secret`, `access_token_key`, and `access_token_secret`. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/11.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/11.md new file mode 100644 index 00000000..4c384a8d --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/11.md @@ -0,0 +1,24 @@ + + +Import the following libraries: + +- `tweepy` + +- `pandas` + +- `sys` + +- `csv` + +- `WordCloud` and `STOPWORDS` from `wordcloud` + +- `matplotlib` + +- `matplotlib.pyplot` + +- `string` + +- `re` + +- `PIL` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/111.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/111.md new file mode 100644 index 00000000..713c4a5f --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/111.md @@ -0,0 +1,36 @@ + + +An example of importing libraries is as below: + +```python +import math +``` + +You can import a library and give it a preferred name, as below: + +```python +import math as mt +``` + +Import the following libraries: + +- `tweepy` + +- `pandas` + +- `sys` + +- `csv` + +- `WordCloud` and `STOPWORDS` from `wordcloud` + +- `matplotlib` + +- `matplotlib.pyplot` + +- `string` + +- `re` + +- `PIL` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/12.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/12.md new file mode 100644 index 00000000..5ba73d1a --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/12.md @@ -0,0 +1,7 @@ + + +Head over to your Twitter Developer Account and create an app. After your app is created, you will see a new page that shows all the information you need. + +![alt](https://python-twitter.readthedocs.io/en/latest/_images/python-twitter-app-creation-part2.png) + +Copy the information needed and declare `consumer_key`, `consumer_secret`, `access_token_key`, and `access_token_secret`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/121.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/121.md new file mode 100644 index 00000000..574b7cdd --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/121.md @@ -0,0 +1,6 @@ + + +Head over to your Twitter Developer Account and create an app. Fill out the fields on the next page that looks like this: + +![alt](https://python-twitter.readthedocs.io/en/latest/_images/python-twitter-app-creation-part1.png) + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/122.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/122.md new file mode 100644 index 00000000..4af68c35 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/122.md @@ -0,0 +1,17 @@ + + +After your app is created, you will see a new page that shows all the information you need. + +![alt](https://python-twitter.readthedocs.io/en/latest/_images/python-twitter-app-creation-part2.png) + +Copy the information needed and declare the keys as follows: + +```python +consumer_key = '' +consumer_secret = '' +access_token_key = '' +access_token_secret = '' +``` + + + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/2.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/2.md new file mode 100644 index 00000000..1f43d941 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/2.md @@ -0,0 +1,8 @@ + + +The next thing we want to do is to create a function to extract tweets. Define a function `get_tweets(username)` that obtains the tweets from the user with username indicated in the parenthesis. + +In our `get_tweets(username)` function, we first get authorization to our consumer key and consumer secret by declaring the variable `auth` using the `tweepy.OAuthHandler` function imported from `tweepy`. Then, we want to access to the user's access key and access secret by using the`auth.set_acess_token` function. + +After we are done with that, we call the API by declaring the variable `api` using the `tweepy.API` function. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/21.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/21.md new file mode 100644 index 00000000..178e89d5 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/21.md @@ -0,0 +1,7 @@ + + +Define a function called `get_tweet()` which takes the parameter `username`. Then, gain authorization to the consumer key and consumer secret by using the function `OAuthHandler()` from the `tweepy` library. + +The next thing we want to do is to gain access to the access key and access secret. We do so by using the `set_access_token()` function. + +Once we are done with the authorization procedure, we move on by calling the API by calling `tweepy.API()`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/211.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/211.md new file mode 100644 index 00000000..f0f50ef6 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/211.md @@ -0,0 +1,20 @@ + + +Define a function called `get_tweet()` which takes the parameter `username` as below: + +```python +def get_tweet(username): +``` + +Under that function, we gain authorization to the consumer key and consumer secret by using the function `OAuthHandler()` from the `tweepy` library as below: + +```python +auth = tweepy.OAuthHandler(consumer_key,consumer_secret) +``` + +After that, we want to gain access to the access key and the access secret. Use the `set_access_token()` function to do the following: + +```python +auth.set_access_token(access_token_key,access_token_secret) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/212.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/212.md new file mode 100644 index 00000000..409c22de --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/212.md @@ -0,0 +1,8 @@ + + +The next thing we want to move on to is to call the Twitter API. Do so by the following: + +```python +api = tweepy.API(auth) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/3.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/3.md new file mode 100644 index 00000000..96345795 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/3.md @@ -0,0 +1,9 @@ + + +For our next step, we want to obtain a number of tweets from the user and write it to a new csv file from the list of tweets. + +To do that, we first declare an empty list and name it `tfile`. Then, create a for loop to access the items in `tweepy.Cursor()` and append tweet data into the `tfile` list. The information that we want to append into `tfile` are `username`, `tweet.id_str`, `tweet.source`, `tweet.created_at`, `tweet.retweet_count`, `tweet.favourite_count`, and `tweet.text.encode("utf-8")`. + +Once we have all our data we need in our `tfile` list, we copy them into a new csv file. Declare a variable `outfile` that names our new .csv file. Copy the data from `tfile` into the .csv file by using the `open` and `writerow` functions. + +Once we are done with this, we have completed our `get_tweet()` function and we can move on to define our main function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/31.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/31.md new file mode 100644 index 00000000..7468015e --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/31.md @@ -0,0 +1,4 @@ + + +Create a list called `tfile`. Then, create a `for` loop to access the items in the user's timeline by calling `tweepy.Cursor(api.user_timeline,screen_name= username).items()`. Within the `for` loop, use the `append()` function on `tfile` to append `username`, `tweet.id_str`, `tweet.source`, `tweet.created_at`, `tweet.retweet_count`, `tweet.favourite_count`, and `tweet.text.encode("utf-8")`. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/311.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/311.md new file mode 100644 index 00000000..d6fee25b --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/311.md @@ -0,0 +1,21 @@ + + +Create a list and name it `tfile` by doing the following: + +```python +tfile = [] +``` + +Then, use a for loop to access the items in the user's timeline: + +```python +for tweet in tweepy.Cursor(api.user_timeline,screen_name=username).itms(): +``` + +In the for loop, append the `tfile` with the append function: + +```python +tfile.append() +``` + +The data that we want to append are `username`, `tweet.id_str`, `tweet.source`, `tweet.created_at`, `tweet.retweet_count`, `tweet.favourite_count`, and `tweet.text.encode("utf-8")`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/32.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/32.md new file mode 100644 index 00000000..fe884e5c --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/32.md @@ -0,0 +1,9 @@ + + +After obtaining tweet data into `tfile`, we want to copy the data into a .csv file. To do so, we create a .csv file and open it by using the following code: + +```python +with open(file,'w+') as file: +``` + +Then, copy the data from `tfile` by using the `writerows(tfile)` function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/321.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/321.md new file mode 100644 index 00000000..9d428e0b --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/321.md @@ -0,0 +1,3 @@ + + +To create a .csv file, we declare a variable `outfile` and store the name of the .csv file as `username + "_tweets_V1.csv"`. Then type `print("writing to " + outfile)` in the following line to make sure that we are writing to our .csv file. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/322.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/322.md new file mode 100644 index 00000000..843bb4de --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/322.md @@ -0,0 +1,18 @@ + + +Open and write in the .csv file by using the following line of code: + +```python +with open(outfile,'w+') as file: +``` + +Under the opened file, use the `csv.writer(file,delimeter)`function to specify how our data should be separated. In this case, we want them to be separated by a comma. Declare this function in a variable called `writer`. + +Using `writer`, we want to write in our .csv file. To make our data tidy and easy to understand, we write the categories on the first row of the .csv file and then add the data from `tfile` in the rows below it as shown: + +```python +writer.writerow(['User_Name','Tweet_ID','Source','Created_date','Retweet_count', + 'Favourite_count','Tweet']) +writer.writerow(tfile) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/4.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/4.md new file mode 100644 index 00000000..4fb16204 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/4.md @@ -0,0 +1,12 @@ + + +The next thing we will move on to is to create our main function. This function utilizes the tweets we obtained into a .csv file in the previous function, cleanse them, and output a Wordcloud based on the highest number of repeated words. + +To do that, we first define our `main()` function. In that function, we start by obtaining the tweet-filled .csv file with the `get_tweets()` function we defined earlier. + +Then, you should pick a celebrity that you want to examine the tweets of, and pass the company's Twitter handle into `get_tweets()`. + +Then, use the `read_csv()` function from the `pandas`library. + +Please leave the code utilizing the `re` library inside of `main()`. Also please make sure you name your object from `read_csv` "bg". Bear in mind the "cleaned" data will be in the DataFrame "bg3". + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/41.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/41.md new file mode 100644 index 00000000..e24d4367 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/41.md @@ -0,0 +1,3 @@ + + +The next step we want to do is to define a `main()` function and do the rest of our tasks there. To read the .csv file that we generated from the `get_tweets()` function, we declare a variable `bg` that calls the function `read_csv()` from the `pandas` library. Print out the first 5 rows of data from `bg` using the `head()` function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/411.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/411.md new file mode 100644 index 00000000..d6b0fb37 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/411.md @@ -0,0 +1,16 @@ + + +The next thing we want to do is to define a `main()` function as follows: + +```python +def main(): +``` + + + +To generate the .csv file under the `main()` function that obtains tweets from a certain user, call the function `get_tweets()` as below: + +```python +get_tweets() +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/412.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/412.md new file mode 100644 index 00000000..49648350 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/412.md @@ -0,0 +1,14 @@ + + +Read the .csv file generated by the `get_tweets()` function by declaring a variable that calls the `read_csv()` function. The `read_csv()` function works like this: + +```python +bg = pd.read_csv(,encoding='utf-8') +``` + +Print the first `n` rows from your .csv file to make sure everything is going smoothly by using the `print()` and `head()` function like this: + +```python +print(bg.head(n)) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/42.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/42.md new file mode 100644 index 00000000..72c0962e --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/42.md @@ -0,0 +1,3 @@ + + +After we have obtained our cleansed tweets in `bg2`, we create a new variable `bg3` that makes `bg2` into a data frame using the `DataFrame` function from the `pandas` library. Print out `bg3` to check for the right data frame output. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/421.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/421.md new file mode 100644 index 00000000..69045e59 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/421.md @@ -0,0 +1,9 @@ + + +After obtaining our cleansed tweets in `bg2`, we create a new variable `bg3` to form a data frame for `bg2` as follows: + +```python +bg3 = pd.DataFrame(bg2, columns = ['tweet']) +``` + +Additionally, print out `bg3` to make sure we have the data frame output that we want. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/5.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/5.md new file mode 100644 index 00000000..f9b27878 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/5.md @@ -0,0 +1,3 @@ + + +Our last main step is to create a Wordcloud based on the data frame of cleansed tweets. To do that, use the functions from `matplotlib`, `wordcloud`, and `matplotlib.pyplot` libraries. After that, compile your entire code and you are done! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/51.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/51.md new file mode 100644 index 00000000..9daca4b0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/51.md @@ -0,0 +1,4 @@ + + +We start by setting the parameters of our Wordcloud plot. Use the `rcParams()` function from the `matplotlib` library to do so. The parameters we want to set are `figure.figsize`, `font.size`, `savefig.dpi`, and `figure.subplot.bottom`. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/511.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/511.md new file mode 100644 index 00000000..55ab9579 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/511.md @@ -0,0 +1,9 @@ + + +We start by setting the parameters of our Wordcloud plot. Use the `rcParams()` function from the `matplotlib` library to do so, as follows: + +```python +mpl.rcParams[''] = +``` + +The parameters we want to set are `figure.figsize`, `font.size`, `savefig.dpi`, and `figure.subplot.bottom`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/52.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/52.md new file mode 100644 index 00000000..1f5f0007 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/52.md @@ -0,0 +1,7 @@ + + +The next thing we want to do is to create the Wordcloud using `STOPWORDS` and `WordCloud` from the `wordcloud` library. + +Set the stopwords using `set(STOPWORDS)`. Then, create a variable `text` to join all the tweets in `bg3`. + +Create the wordcloud using the function `WordCloud().generate(str(text))`. The parameters we want to edit in the `WordCloud()` function are `background_color`, `stopwords`, `max_words`, `max_font_size`, and `random_state`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/521.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/521.md new file mode 100644 index 00000000..53e41333 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/521.md @@ -0,0 +1,16 @@ + + +Now, we want to create the Wordcloud using `STOPWORDS` and `WordCloud` from the `wordcloud` library. We start by setting the stopwords, as follows: + +```python +stopwords = set(STOPWORDS) +``` + +Next, create a variable `text` that joins all the tweets in `bg3`, separated with a space: + +```python +text = " ".join() +``` + + + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/522.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/522.md new file mode 100644 index 00000000..c9a18ce8 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/522.md @@ -0,0 +1,21 @@ + + +We want to set the parameters in our wordcloud by doing the following: + +```python +cloud = WordCloud( + background_color = , + stopwords = stopwords, + max_words = , + max_font_size = , + random_state = ) +``` + +After that, we generate the wordcloud as follows: + +```python +wordcloud = cloud.generate(str(text)) +``` + + + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/53.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/53.md new file mode 100644 index 00000000..a960cafd --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/53.md @@ -0,0 +1,10 @@ + + +After we have created our Wordcloud, we want to display it. To do so, we use functions from the `matplotlib.pyplot` library below: + +- `matplotlib.pyplot.figure()` +- `matplotlib.pyplot.imshow()` +- `matplotlib.pyplot.axis()` +- `matplotlib.pyplot.show()` + +Once you have done the above, you can choose to add another line of code to save the Wordcloud you generated with the `savefig()` function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/531.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/531.md new file mode 100644 index 00000000..c4f5bb76 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/531.md @@ -0,0 +1,22 @@ + + +After we have created our Wordcloud, we want to display it. To do so, we use functions from the `matplotlib.pyplot` library. We start by plotting a figure: + +```python +fig = matplotlib.pyplot.figure(1) +``` + +Then, we adjust some parameters and display our wordcloud by doing the following: + +```python +matplotlib.pyplot.imshow() +matplotlib.pyplot.axis('off') +matplotlib.pyplot.show() +``` + +Once you have done the above, you can choose to add another line of code to save the Wordcloud you generated with the `savefig()` function as shown: + +```python +fig.savefig("",dpi=1400) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/54.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/54.md new file mode 100644 index 00000000..890c6e96 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/54.md @@ -0,0 +1,3 @@ + + +Now that we are done with all our code, we can compile it all together and run it. Congratulations for successfully generating a wordcloud to visualize tweets! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/541.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/541.md new file mode 100644 index 00000000..caee57af --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/541.md @@ -0,0 +1,28 @@ + + +Compile your code in the following manner and you are done! Congratulations! + +```python +#import your libraries +import + +#declare your keys +consumer_key = +consumer_secret = +access_token_key = +access_token_secret = + +#Function to extract tweets +def get_tweets(username): + + + +#Function to generate Wordcloud +def main(): + + + +#Call the main() function +main() +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md new file mode 100644 index 00000000..067e1540 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md @@ -0,0 +1,12 @@ + + +For this lab, we will be analyzing tweets using Twitter's API and `tweepy` package in Python by creating a Word Cloud to observe the frequency of words being used in a company's tweets. + +Analyzing the words used by a company in an increasingly cluttered social media world has many uses. Companies use social media to generate excitement around their products and increase awareness of their company, so the words they choose in their tweets can provide lots of insight into the values of marketing strategies and values of companies on Twitter. How do companies advertise their products? How often do they attack the products of other companies? What kind of feelings are they trying to conjure in relation to their products? Knowing the words used in their tweets, ordered by frequency, will help us paint a picture of a company's marketing on Twitter. + +To do this in Python using `tweepy`, you should start off by importing our necessary libraries. The libraries we will be using are: + +`tweepy`, `pandas`, `sys`, `csv`, `WordCloud` and `STOPWORDS` from `wordcloud`, `matplotlib`, `matplotlib.pyplot`, `string`, `re`, `PIL` + +The next thing we want is to be able to use the python-twitter API client. To do that, you need to acquire a declare a set of application tokens. Name the tokens `consumer_key`, `consumer_secret`, `access_token_key`, and `access_token_secret`. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/11.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/11.md new file mode 100644 index 00000000..4c384a8d --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/11.md @@ -0,0 +1,24 @@ + + +Import the following libraries: + +- `tweepy` + +- `pandas` + +- `sys` + +- `csv` + +- `WordCloud` and `STOPWORDS` from `wordcloud` + +- `matplotlib` + +- `matplotlib.pyplot` + +- `string` + +- `re` + +- `PIL` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/111.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/111.md new file mode 100644 index 00000000..713c4a5f --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/111.md @@ -0,0 +1,36 @@ + + +An example of importing libraries is as below: + +```python +import math +``` + +You can import a library and give it a preferred name, as below: + +```python +import math as mt +``` + +Import the following libraries: + +- `tweepy` + +- `pandas` + +- `sys` + +- `csv` + +- `WordCloud` and `STOPWORDS` from `wordcloud` + +- `matplotlib` + +- `matplotlib.pyplot` + +- `string` + +- `re` + +- `PIL` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/12.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/12.md new file mode 100644 index 00000000..5ba73d1a --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/12.md @@ -0,0 +1,7 @@ + + +Head over to your Twitter Developer Account and create an app. After your app is created, you will see a new page that shows all the information you need. + +![alt](https://python-twitter.readthedocs.io/en/latest/_images/python-twitter-app-creation-part2.png) + +Copy the information needed and declare `consumer_key`, `consumer_secret`, `access_token_key`, and `access_token_secret`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/121.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/121.md new file mode 100644 index 00000000..574b7cdd --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/121.md @@ -0,0 +1,6 @@ + + +Head over to your Twitter Developer Account and create an app. Fill out the fields on the next page that looks like this: + +![alt](https://python-twitter.readthedocs.io/en/latest/_images/python-twitter-app-creation-part1.png) + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/122.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/122.md new file mode 100644 index 00000000..4af68c35 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/122.md @@ -0,0 +1,17 @@ + + +After your app is created, you will see a new page that shows all the information you need. + +![alt](https://python-twitter.readthedocs.io/en/latest/_images/python-twitter-app-creation-part2.png) + +Copy the information needed and declare the keys as follows: + +```python +consumer_key = '' +consumer_secret = '' +access_token_key = '' +access_token_secret = '' +``` + + + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/2.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/2.md new file mode 100644 index 00000000..1f43d941 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/2.md @@ -0,0 +1,8 @@ + + +The next thing we want to do is to create a function to extract tweets. Define a function `get_tweets(username)` that obtains the tweets from the user with username indicated in the parenthesis. + +In our `get_tweets(username)` function, we first get authorization to our consumer key and consumer secret by declaring the variable `auth` using the `tweepy.OAuthHandler` function imported from `tweepy`. Then, we want to access to the user's access key and access secret by using the`auth.set_acess_token` function. + +After we are done with that, we call the API by declaring the variable `api` using the `tweepy.API` function. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/21.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/21.md new file mode 100644 index 00000000..178e89d5 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/21.md @@ -0,0 +1,7 @@ + + +Define a function called `get_tweet()` which takes the parameter `username`. Then, gain authorization to the consumer key and consumer secret by using the function `OAuthHandler()` from the `tweepy` library. + +The next thing we want to do is to gain access to the access key and access secret. We do so by using the `set_access_token()` function. + +Once we are done with the authorization procedure, we move on by calling the API by calling `tweepy.API()`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/211.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/211.md new file mode 100644 index 00000000..f0f50ef6 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/211.md @@ -0,0 +1,20 @@ + + +Define a function called `get_tweet()` which takes the parameter `username` as below: + +```python +def get_tweet(username): +``` + +Under that function, we gain authorization to the consumer key and consumer secret by using the function `OAuthHandler()` from the `tweepy` library as below: + +```python +auth = tweepy.OAuthHandler(consumer_key,consumer_secret) +``` + +After that, we want to gain access to the access key and the access secret. Use the `set_access_token()` function to do the following: + +```python +auth.set_access_token(access_token_key,access_token_secret) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/212.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/212.md new file mode 100644 index 00000000..409c22de --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/212.md @@ -0,0 +1,8 @@ + + +The next thing we want to move on to is to call the Twitter API. Do so by the following: + +```python +api = tweepy.API(auth) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/3.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/3.md new file mode 100644 index 00000000..96345795 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/3.md @@ -0,0 +1,9 @@ + + +For our next step, we want to obtain a number of tweets from the user and write it to a new csv file from the list of tweets. + +To do that, we first declare an empty list and name it `tfile`. Then, create a for loop to access the items in `tweepy.Cursor()` and append tweet data into the `tfile` list. The information that we want to append into `tfile` are `username`, `tweet.id_str`, `tweet.source`, `tweet.created_at`, `tweet.retweet_count`, `tweet.favourite_count`, and `tweet.text.encode("utf-8")`. + +Once we have all our data we need in our `tfile` list, we copy them into a new csv file. Declare a variable `outfile` that names our new .csv file. Copy the data from `tfile` into the .csv file by using the `open` and `writerow` functions. + +Once we are done with this, we have completed our `get_tweet()` function and we can move on to define our main function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/31.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/31.md new file mode 100644 index 00000000..7468015e --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/31.md @@ -0,0 +1,4 @@ + + +Create a list called `tfile`. Then, create a `for` loop to access the items in the user's timeline by calling `tweepy.Cursor(api.user_timeline,screen_name= username).items()`. Within the `for` loop, use the `append()` function on `tfile` to append `username`, `tweet.id_str`, `tweet.source`, `tweet.created_at`, `tweet.retweet_count`, `tweet.favourite_count`, and `tweet.text.encode("utf-8")`. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/311.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/311.md new file mode 100644 index 00000000..d6fee25b --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/311.md @@ -0,0 +1,21 @@ + + +Create a list and name it `tfile` by doing the following: + +```python +tfile = [] +``` + +Then, use a for loop to access the items in the user's timeline: + +```python +for tweet in tweepy.Cursor(api.user_timeline,screen_name=username).itms(): +``` + +In the for loop, append the `tfile` with the append function: + +```python +tfile.append() +``` + +The data that we want to append are `username`, `tweet.id_str`, `tweet.source`, `tweet.created_at`, `tweet.retweet_count`, `tweet.favourite_count`, and `tweet.text.encode("utf-8")`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/32.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/32.md new file mode 100644 index 00000000..fe884e5c --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/32.md @@ -0,0 +1,9 @@ + + +After obtaining tweet data into `tfile`, we want to copy the data into a .csv file. To do so, we create a .csv file and open it by using the following code: + +```python +with open(file,'w+') as file: +``` + +Then, copy the data from `tfile` by using the `writerows(tfile)` function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/321.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/321.md new file mode 100644 index 00000000..9d428e0b --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/321.md @@ -0,0 +1,3 @@ + + +To create a .csv file, we declare a variable `outfile` and store the name of the .csv file as `username + "_tweets_V1.csv"`. Then type `print("writing to " + outfile)` in the following line to make sure that we are writing to our .csv file. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/322.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/322.md new file mode 100644 index 00000000..843bb4de --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/322.md @@ -0,0 +1,18 @@ + + +Open and write in the .csv file by using the following line of code: + +```python +with open(outfile,'w+') as file: +``` + +Under the opened file, use the `csv.writer(file,delimeter)`function to specify how our data should be separated. In this case, we want them to be separated by a comma. Declare this function in a variable called `writer`. + +Using `writer`, we want to write in our .csv file. To make our data tidy and easy to understand, we write the categories on the first row of the .csv file and then add the data from `tfile` in the rows below it as shown: + +```python +writer.writerow(['User_Name','Tweet_ID','Source','Created_date','Retweet_count', + 'Favourite_count','Tweet']) +writer.writerow(tfile) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/4.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/4.md new file mode 100644 index 00000000..93a84433 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/4.md @@ -0,0 +1,12 @@ + + +The next thing we will move on to is to create our main function. This function utilizes the tweets we obtained into a .csv file in the previous function, cleanse them, and output a Wordcloud based on the highest number of repeated words. + +To do that, we first define our `main()` function. In that function, we start by obtaining the tweet-filled .csv file with the `get_tweets()` function we defined earlier. + +Then, you should pick a company that you want to examine the marketing strategy of, and pass the company's Twitter handle into `get_tweets()`. + +Then, use the `read_csv()` function from the `pandas`library. + +Please leave the code utilizing the `re` library inside of `main()`. Also please make sure you name your object from `read_csv` "bg". Bear in mind the "cleaned" data will be in the DataFrame "bg3". + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/41.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/41.md new file mode 100644 index 00000000..e24d4367 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/41.md @@ -0,0 +1,3 @@ + + +The next step we want to do is to define a `main()` function and do the rest of our tasks there. To read the .csv file that we generated from the `get_tweets()` function, we declare a variable `bg` that calls the function `read_csv()` from the `pandas` library. Print out the first 5 rows of data from `bg` using the `head()` function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/411.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/411.md new file mode 100644 index 00000000..d6b0fb37 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/411.md @@ -0,0 +1,16 @@ + + +The next thing we want to do is to define a `main()` function as follows: + +```python +def main(): +``` + + + +To generate the .csv file under the `main()` function that obtains tweets from a certain user, call the function `get_tweets()` as below: + +```python +get_tweets() +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/412.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/412.md new file mode 100644 index 00000000..49648350 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/412.md @@ -0,0 +1,14 @@ + + +Read the .csv file generated by the `get_tweets()` function by declaring a variable that calls the `read_csv()` function. The `read_csv()` function works like this: + +```python +bg = pd.read_csv(,encoding='utf-8') +``` + +Print the first `n` rows from your .csv file to make sure everything is going smoothly by using the `print()` and `head()` function like this: + +```python +print(bg.head(n)) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/42.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/42.md new file mode 100644 index 00000000..72c0962e --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/42.md @@ -0,0 +1,3 @@ + + +After we have obtained our cleansed tweets in `bg2`, we create a new variable `bg3` that makes `bg2` into a data frame using the `DataFrame` function from the `pandas` library. Print out `bg3` to check for the right data frame output. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/421.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/421.md new file mode 100644 index 00000000..69045e59 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/421.md @@ -0,0 +1,9 @@ + + +After obtaining our cleansed tweets in `bg2`, we create a new variable `bg3` to form a data frame for `bg2` as follows: + +```python +bg3 = pd.DataFrame(bg2, columns = ['tweet']) +``` + +Additionally, print out `bg3` to make sure we have the data frame output that we want. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/5.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/5.md new file mode 100644 index 00000000..f9b27878 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/5.md @@ -0,0 +1,3 @@ + + +Our last main step is to create a Wordcloud based on the data frame of cleansed tweets. To do that, use the functions from `matplotlib`, `wordcloud`, and `matplotlib.pyplot` libraries. After that, compile your entire code and you are done! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/51.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/51.md new file mode 100644 index 00000000..9daca4b0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/51.md @@ -0,0 +1,4 @@ + + +We start by setting the parameters of our Wordcloud plot. Use the `rcParams()` function from the `matplotlib` library to do so. The parameters we want to set are `figure.figsize`, `font.size`, `savefig.dpi`, and `figure.subplot.bottom`. + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/511.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/511.md new file mode 100644 index 00000000..55ab9579 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/511.md @@ -0,0 +1,9 @@ + + +We start by setting the parameters of our Wordcloud plot. Use the `rcParams()` function from the `matplotlib` library to do so, as follows: + +```python +mpl.rcParams[''] = +``` + +The parameters we want to set are `figure.figsize`, `font.size`, `savefig.dpi`, and `figure.subplot.bottom`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/52.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/52.md new file mode 100644 index 00000000..1f5f0007 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/52.md @@ -0,0 +1,7 @@ + + +The next thing we want to do is to create the Wordcloud using `STOPWORDS` and `WordCloud` from the `wordcloud` library. + +Set the stopwords using `set(STOPWORDS)`. Then, create a variable `text` to join all the tweets in `bg3`. + +Create the wordcloud using the function `WordCloud().generate(str(text))`. The parameters we want to edit in the `WordCloud()` function are `background_color`, `stopwords`, `max_words`, `max_font_size`, and `random_state`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/521.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/521.md new file mode 100644 index 00000000..53e41333 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/521.md @@ -0,0 +1,16 @@ + + +Now, we want to create the Wordcloud using `STOPWORDS` and `WordCloud` from the `wordcloud` library. We start by setting the stopwords, as follows: + +```python +stopwords = set(STOPWORDS) +``` + +Next, create a variable `text` that joins all the tweets in `bg3`, separated with a space: + +```python +text = " ".join() +``` + + + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/522.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/522.md new file mode 100644 index 00000000..c9a18ce8 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/522.md @@ -0,0 +1,21 @@ + + +We want to set the parameters in our wordcloud by doing the following: + +```python +cloud = WordCloud( + background_color = , + stopwords = stopwords, + max_words = , + max_font_size = , + random_state = ) +``` + +After that, we generate the wordcloud as follows: + +```python +wordcloud = cloud.generate(str(text)) +``` + + + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/53.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/53.md new file mode 100644 index 00000000..a960cafd --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/53.md @@ -0,0 +1,10 @@ + + +After we have created our Wordcloud, we want to display it. To do so, we use functions from the `matplotlib.pyplot` library below: + +- `matplotlib.pyplot.figure()` +- `matplotlib.pyplot.imshow()` +- `matplotlib.pyplot.axis()` +- `matplotlib.pyplot.show()` + +Once you have done the above, you can choose to add another line of code to save the Wordcloud you generated with the `savefig()` function. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/531.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/531.md new file mode 100644 index 00000000..c4f5bb76 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/531.md @@ -0,0 +1,22 @@ + + +After we have created our Wordcloud, we want to display it. To do so, we use functions from the `matplotlib.pyplot` library. We start by plotting a figure: + +```python +fig = matplotlib.pyplot.figure(1) +``` + +Then, we adjust some parameters and display our wordcloud by doing the following: + +```python +matplotlib.pyplot.imshow() +matplotlib.pyplot.axis('off') +matplotlib.pyplot.show() +``` + +Once you have done the above, you can choose to add another line of code to save the Wordcloud you generated with the `savefig()` function as shown: + +```python +fig.savefig("",dpi=1400) +``` + diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/54.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/54.md new file mode 100644 index 00000000..890c6e96 --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/54.md @@ -0,0 +1,3 @@ + + +Now that we are done with all our code, we can compile it all together and run it. Congratulations for successfully generating a wordcloud to visualize tweets! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/541.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/541.md new file mode 100644 index 00000000..caee57af --- /dev/null +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/541.md @@ -0,0 +1,28 @@ + + +Compile your code in the following manner and you are done! Congratulations! + +```python +#import your libraries +import + +#declare your keys +consumer_key = +consumer_secret = +access_token_key = +access_token_secret = + +#Function to extract tweets +def get_tweets(username): + + + +#Function to generate Wordcloud +def main(): + + + +#Call the main() function +main() +``` + From 6461d50889521c1ea49b8d2d27a7ef969c59ff9b Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 13 Feb 2020 00:36:35 -0800 Subject: [PATCH 02/23] Week 2 Labs --- .../Visualizing Tweets - Celebrities/1.md | 2 +- .../Visualizing Tweets - Companies/1.md | 2 +- .../Week 2/Twitter Hashtag Frequency/1.md | 15 ++++++ .../Week 2/Twitter Hashtag Frequency/11.md | 1 + .../Week 2/Twitter Hashtag Frequency/111.md | 12 +++++ .../Week 2/Twitter Hashtag Frequency/112.md | 30 +++++++++++ .../Week 2/Twitter Hashtag Frequency/12.md | 9 ++++ .../Week 2/Twitter Hashtag Frequency/121.md | 9 ++++ .../Week 2/Twitter Hashtag Frequency/122.md | 18 +++++++ .../Week 2/Twitter Hashtag Frequency/123.md | 9 ++++ .../Week 2/Twitter Hashtag Frequency/2.md | 5 ++ .../Week 2/Twitter Hashtag Frequency/21.md | 11 ++++ .../Week 2/Twitter Hashtag Frequency/22.md | 3 ++ .../Week 2/Twitter Hashtag Frequency/221.md | 15 ++++++ .../Week 2/Twitter Hashtag Frequency/222.md | 22 ++++++++ .../Week 2/Twitter Hashtag Frequency/3.md | 5 ++ .../Week 2/Twitter Hashtag Frequency/311.md | 11 ++++ .../Week 2/Twitter Hashtag Frequency/312.md | 10 ++++ .../Week 2/Twitter Hashtag Frequency/313.md | 15 ++++++ .../Week 2/Twitter Hashtag Frequency/32.md | 21 ++++++++ .../Week 2/Twitter Hashtag Frequency/33.md | 15 ++++++ .../Week 2/Twitter Hashtag Frequency/331.md | 16 ++++++ .../Week 2/Twitter Hashtag Frequency/332.md | 10 ++++ .../Week 2/Twitter Hashtag Frequency/333.md | 51 +++++++++++++++++++ .../Week 2/Twitter Hashtag Frequency/4.md | 6 +++ .../Week 2/Twitter Hashtag Frequency/5.md | 5 ++ .../Week 2/Twitter Hashtag Frequency/51.md | 12 +++++ .../Week 2/Twitter Hashtag Frequency/52.md | 24 +++++++++ .../labs/Week 2/Twitter Word Frequency/1.md | 11 ++++ .../labs/Week 2/Twitter Word Frequency/11.md | 1 + .../labs/Week 2/Twitter Word Frequency/111.md | 12 +++++ .../labs/Week 2/Twitter Word Frequency/112.md | 30 +++++++++++ .../labs/Week 2/Twitter Word Frequency/12.md | 9 ++++ .../labs/Week 2/Twitter Word Frequency/121.md | 9 ++++ .../labs/Week 2/Twitter Word Frequency/122.md | 18 +++++++ .../labs/Week 2/Twitter Word Frequency/123.md | 9 ++++ .../labs/Week 2/Twitter Word Frequency/2.md | 5 ++ .../labs/Week 2/Twitter Word Frequency/21.md | 11 ++++ .../labs/Week 2/Twitter Word Frequency/22.md | 3 ++ .../labs/Week 2/Twitter Word Frequency/221.md | 15 ++++++ .../labs/Week 2/Twitter Word Frequency/222.md | 22 ++++++++ .../labs/Week 2/Twitter Word Frequency/3.md | 5 ++ .../labs/Week 2/Twitter Word Frequency/311.md | 11 ++++ .../labs/Week 2/Twitter Word Frequency/312.md | 10 ++++ .../labs/Week 2/Twitter Word Frequency/313.md | 15 ++++++ .../labs/Week 2/Twitter Word Frequency/32.md | 21 ++++++++ .../labs/Week 2/Twitter Word Frequency/33.md | 15 ++++++ .../labs/Week 2/Twitter Word Frequency/331.md | 16 ++++++ .../labs/Week 2/Twitter Word Frequency/332.md | 10 ++++ .../labs/Week 2/Twitter Word Frequency/333.md | 51 +++++++++++++++++++ .../labs/Week 2/Twitter Word Frequency/4.md | 5 ++ .../labs/Week 2/Twitter Word Frequency/41.md | 31 +++++++++++ .../labs/Week 2/Twitter Word Frequency/5.md | 5 ++ .../labs/Week 2/Twitter Word Frequency/51.md | 12 +++++ .../labs/Week 2/Twitter Word Frequency/52.md | 24 +++++++++ 55 files changed, 748 insertions(+), 2 deletions(-) create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/11.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/111.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/112.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/12.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/121.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/122.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/123.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/2.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/21.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/22.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/221.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/222.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/3.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/311.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/312.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/313.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/32.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/33.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/331.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/332.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/333.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/4.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/5.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/51.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/52.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/11.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/111.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/112.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/12.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/121.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/122.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/123.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/21.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/22.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/221.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/222.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/3.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/311.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/312.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/313.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/32.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/33.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/331.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/332.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/333.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/41.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/5.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/51.md create mode 100644 Module_Twitter_API/labs/Week 2/Twitter Word Frequency/52.md diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md index 45e44817..a25f4583 100644 --- a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Celebrities/1.md @@ -4,7 +4,7 @@ For this lab, we will be analyzing tweets using Twitter's API and `tweepy` packa Analyzing the words used by a celebrity in an increasingly cluttered social media world has many uses. -In this day and age, having a prominent social media presence can mean the difference for celebrities' public persona. A celebrity can use social media to generate excitement from millions of fans on Twitter, and if done right, propel their fame to new heights. Conversely, celebrities have to be careful about what they post on a site like Twitter, because one offensive tweet will get viral for the wrong reasons and destroy their reputation, not just in social media but in real life as well. Therefore, the words that celebrities choose when tweeting are vitally important, to cultivate an online persona and propel their own fame. Seeing the most common words in their tweets can help us find common trends in their tweets and determine what kind of persona they wish to conjure on social media. +In this day and age, having a prominent social media presence can mean the difference for celebrities' public persona. A celebrity can use social media to generate excitement from millions of fans on Twitter, and if done right, propel their fame to new heights. Conversely, celebrities have to be careful about what they post on a site like Twitter, because one offensive tweet will get viral for the wrong reasons and destroy their reputation, not just in social media but in real life as well. Therefore, the words that celebrities choose when tweeting are vitally important, to cultivate an online persona and propel their own fame. Seeing a word cloud of the words in their tweets can start to help us find common trends in their tweets and determine what kind of persona they wish to conjure on social media. To do this in Python using `tweepy`, you should start off by importing our necessary libraries. The libraries we will be using are: diff --git a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md index 067e1540..02db1ccd 100644 --- a/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md +++ b/Module_Twitter_API/labs/Week 1/Visualizing Tweets - Companies/1.md @@ -2,7 +2,7 @@ For this lab, we will be analyzing tweets using Twitter's API and `tweepy` package in Python by creating a Word Cloud to observe the frequency of words being used in a company's tweets. -Analyzing the words used by a company in an increasingly cluttered social media world has many uses. Companies use social media to generate excitement around their products and increase awareness of their company, so the words they choose in their tweets can provide lots of insight into the values of marketing strategies and values of companies on Twitter. How do companies advertise their products? How often do they attack the products of other companies? What kind of feelings are they trying to conjure in relation to their products? Knowing the words used in their tweets, ordered by frequency, will help us paint a picture of a company's marketing on Twitter. +Analyzing the words used by a company in an increasingly cluttered social media world has many uses. Companies use social media to generate excitement around their products and increase awareness of their company, so the words they choose in their tweets can provide lots of insight into the values of marketing strategies and values of companies on Twitter. How do companies advertise their products? How often do they attack the products of other companies? What kind of feelings are they trying to conjure in relation to their products? Seeing a word cloud of their most common words is an easy way to help us paint a picture of a company's marketing on Twitter. To do this in Python using `tweepy`, you should start off by importing our necessary libraries. The libraries we will be using are: diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md new file mode 100644 index 00000000..77785a76 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md @@ -0,0 +1,15 @@ + + +For this lab we will utilize the skills you've gained working with APIs to visualize tweets using the **tweepy** Twitter API. + +The idea is simple, given a topic, all hashtags with greater than 5% frequency pertaining to that topic are plotted in a pie graph. All hashtags with less than 5% frequency fall under an "Other" category. + +Hashtags provide an efficient way of deducing how tweeters feel about the topic they are tweeting about, since Twitter users use hashtags to summarize their tweets, often with more emotion. Therefore hashtags provide a sufficient summary of the tweet - there is a lesser need to process every character and word of a tweet if the hashtags are available. + +By seeing the most common hashtags associated with a topic, we can evaluate what Twitter users are discussing under the scope of a greater topic and how people feel about the topic at hand. It's easy to get caught in our own echo chambers on social media, and analyzing the most common hashtags across *all* tweets for a certain topic helps us analyze the feelings behind a topic in a more objective manner. + +Here is an example of what we will be aiming to accomplish at the end of this lab: + +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/pieplot.png) + + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/11.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/11.md new file mode 100644 index 00000000..f3a5f03b --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/11.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/111.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/111.md new file mode 100644 index 00000000..80112577 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/111.md @@ -0,0 +1,12 @@ + + +If you're on Anaconda installing the Tweepy API is simple, just type the following: + +``` python +conda install tweepy +``` + +After installing the API you will also have to create a developer account with Twitter in order to access the API, this process is quick and straightforward. Just click [this](https://developer.twitter.com/en/apply-for-access.html) link to get started. + + + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/112.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/112.md new file mode 100644 index 00000000..7f14cc6e --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/112.md @@ -0,0 +1,30 @@ + + +The following packages will need to be installed in order to complete the necessary functions of the lab. By now you are already familiar with loading Python packages thanks to your previous labs. + +``` python +import os +import pandas as pd +import matplotlib.pyplot as plt +import seaborn as sns +import itertools +import collections + +import tweepy as tw +import nltk +from nltk.corpus import stopwords +import re +import networkx + +import warnings + +import warnings +warnings.filterwarnings("ignore") + +sns.set(font_scale=1.5) +sns.set_style("whitegrid") +``` + +As we progress thourgh the lab you will see how all these packages play a key role in developing our program. + + \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/12.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/12.md new file mode 100644 index 00000000..62065a92 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/12.md @@ -0,0 +1,9 @@ + + +In order to complete the various functions and methods we will perform, we need to login to twitter through our program. + +To complete this we need to go through 3 simple steps: + +1. Define your search keys +2. Create the access token to login +3. Finally, accessing the API \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/121.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/121.md new file mode 100644 index 00000000..a51a01ac --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/121.md @@ -0,0 +1,9 @@ + + +Defining the keys to login is simple, the information you need is all provided when you're developer account is created. Type the following to store it in a variable + +``` python +consumer_key= 'yourkeyhere' +consumer_secret= 'yourkeyhere' +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/122.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/122.md new file mode 100644 index 00000000..f60cd59b --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/122.md @@ -0,0 +1,18 @@ + + +Now we must create our access token, this is a key step to complete the login process. + +First, store the token values in a variable: + +``` python +access_token= 'yourkeyhere' +access_token_secret= 'yourkeyhere' +``` + +Second, use the OAuthHandler() and set_access_token() methods to create the instance that will allow login. + +``` python +auth = tw.OAuthHandler(consumer_key, consumer_secret) +auth.set_access_token(access_token, access_token_secret) +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/123.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/123.md new file mode 100644 index 00000000..64d068fd --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/123.md @@ -0,0 +1,9 @@ + + +Now that we have created our access token we can finally access the API, this can be done in a simple line. + +``` python +api = tw.API(auth, wait_on_rate_limit=True) + +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/2.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/2.md new file mode 100644 index 00000000..c85e0037 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/2.md @@ -0,0 +1,5 @@ + + +Now that we've authenticated we're ready to search for tweets. Let's start by searching for all tweets surrounding the topic of climate change. ("climate change" being your query string) + +![sample image](https://www.diggitmagazine.com/sites/default/files/styles/inline_image/public/Climate%20change%20photo_1.jpg?itok=2BfiKsqU) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/21.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/21.md new file mode 100644 index 00000000..e8156afc --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/21.md @@ -0,0 +1,11 @@ + + +In order to search for tweets under our desired hashtag, we will use the -filter method to find tweets under the climate change hashtag. + +In order to accomplish we write the following: + +``` python +search_term = "#climate+change -filter:retweets" +``` + +Here we are telling the **tweepy** API to filter for recent tweets containg the climate change hashtag \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/22.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/22.md new file mode 100644 index 00000000..3cd01ff2 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/22.md @@ -0,0 +1,3 @@ + + +Now that we've found the recent tweets containg the hashtags that we will eventually analyze, we need to store the tweets in an organized manner for analysis. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/221.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/221.md new file mode 100644 index 00000000..6175be94 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/221.md @@ -0,0 +1,15 @@ + + +For our analysis we need an accurate sample size for credible findings. We will grab 1,000 tweets under the climate change hashtag for our analysis. + +To accomplish this we will use the Cursor method to iterate through the tweets, you may remember seeing this method from a previous lab. + +``` python +tweets = tw.Cursor(api.search, + q=search_term, + lang="en", + since='2018-11-01').items(1000) +``` + +Using the Cursor method tell the iterator to search through the api, with the climate change hashtag, in english. There will be 1000 items in this iteration from tweets tweeted since Novemeber 1st 2018. + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/222.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/222.md new file mode 100644 index 00000000..87dc80d7 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/222.md @@ -0,0 +1,22 @@ + + +Now we can use list comprehension to iterate through our recently found items in a list. + +``` python +all_tweets = [tweet.text for tweet in tweets] +``` + +Here's yet another example of when list comprehension comes in handy. Especially in data analysis. + +Now let's see the output we get... + +``` python +all_tweets[:5] +# Below is the output of the first 5 results +['@InsuranceBureau Hey! Yoohoo! Hey! @InsuranceBureau! \nMaybe sometime before today, and everyday from now on, you sh… https://t.co/sWc2XT1DO8', + 'Our rulers are golfing and trail running while human civilization burns down. \n\nNew piece by @KateAronoff. #climate… https://t.co/R6HZ78oK67', + '"These findings lend themselves to a somewhat controversial idea: that we might be able to manipulate these marine… https://t.co/71w3y6fWfA', + 'Information based on proven data about #climate change and how this affects #waterAvailability is so important! Tha… https://t.co/YDe1k1sJKj', + 'Here’s what @EmoryUniversity is doing to tackle #climate change. You can get involved by visiting… https://t.co/eQsGGsob1J'] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/3.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/3.md new file mode 100644 index 00000000..68392164 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/3.md @@ -0,0 +1,5 @@ + + +As you saw from the output of our lists there are links to the tweets. While this may be nice to track the source of the tweets it will be a hinderance when parsing through the list for analysis. + +We will use regular expressions to accomplish the data cleaning. Throughout the previous labs you have gone through you may by now know that cleaning data is the longest portion of analysis projects. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/311.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/311.md new file mode 100644 index 00000000..1602b646 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/311.md @@ -0,0 +1,11 @@ + + +You may remember seeing ```import re``` while we were loading our packages earlier. Re stands for ```regular expressions```. Regular expressions are a special syntax that is used to identify patterns in a string. + +While this lesson will not cover regular expressions, it is helpful to understand that this syntax below: + +``` +([^0-9A-Za-z \t])|(\w+:\/\/\S+) +``` + +Tells the search to find all strings that look like a URL, and replace it with nothing – `""`. It also removes other punctionation including hashtags - `#`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/312.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/312.md new file mode 100644 index 00000000..e7ed3ba9 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/312.md @@ -0,0 +1,10 @@ + + +`re.sub` allows you to substitute a selection of characters defined using a regular expression, with something else. + +In the function defined below, this line takes the text in each tweet and replaces the URL with nothing: + +``` python +re.sub("([^0-9A-Za-z \t])|(\w+:\/\/\S+)", "", tweet +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/313.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/313.md new file mode 100644 index 00000000..9ad6e696 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/313.md @@ -0,0 +1,15 @@ + + +Using the re.sub method we just looked at we can create a function that removes urls from the items of our list. + +```python +def remove_url(txt): + return " ".join(re.sub("([^0-9A-Za-z \t])|(\w+:\/\/\S+)", "", txt).split()) +``` + +This is a simple function that accomplishes quiet a lot. We replace URLs found ina. text string with nothing. + +The parameters that the function takes in is a text string which we'd like to parse and remove urls from. The function returns the same txt string with url's removed. + + + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/32.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/32.md new file mode 100644 index 00000000..61642fe5 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/32.md @@ -0,0 +1,21 @@ + + +Now that we have finished removing urls from our tweets we can add them to a list for analysis. + +Again, we will use list comprehension to accomplish this task: + +``` python +all_tweets_no_urls = [remove_url(tweet) for tweet in all_tweets] +all_tweets_no_urls[:5] +``` + +Displaying the output of our first 5 elements of the list we see a much cleaner result: + +```python +['InsuranceBureau Hey Yoohoo Hey InsuranceBureau Maybe sometime before today and everyday from now on you sh', + 'Our rulers are golfing and trail running while human civilization burns down New piece by KateAronoff climate', + 'These findings lend themselves to a somewhat controversial idea that we might be able to manipulate these marine', + 'Information based on proven data about climate change and how this affects waterAvailability is so important Tha', + 'Heres what EmoryUniversity is doing to tackle climate change You can get involved by visiting'] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/33.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/33.md new file mode 100644 index 00000000..ff6ab3fc --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/33.md @@ -0,0 +1,15 @@ + + +Another challenge we will address is capitalization which becomes a challenge with data analysis for text data. If you are trying to create a list of unique words in your tweets, words with capitalization will be different from words that are all lowercase. + +Here's an example: + +```python +# Note how capitalization impacts unique returned values +ex_list = ["Dog", "dog", "dog", "cat", "cat", ","] + +# Get unique elements in the list +set(ex_list) +{',', 'Dog', 'cat', 'dog'} +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/331.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/331.md new file mode 100644 index 00000000..6b42bcc0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/331.md @@ -0,0 +1,16 @@ + + +To begin to remedy this issue we can make each word lowercase using the string method `.lower()`. In the code below, this method is applied using a list comprehension. + +```python +# Note how capitalization impacts unique returned values +words_list = ["Dog", "dog", "dog", "cat", "cat", ","] + +# Make all elements in the list lowercase +lower_case = [word.lower() for word in words_list] + +# Get all elements in the list +lower_case +['dog', 'dog', 'dog', 'cat', 'cat', ','] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/332.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/332.md new file mode 100644 index 00000000..02802ae3 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/332.md @@ -0,0 +1,10 @@ + + +Now all of the words in your list are lowercase. You can again use `set()` function to return only unique words. + +```python +# Now you have only unique words +set(lower_case) +{',', 'cat', 'dog'} +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/333.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/333.md new file mode 100644 index 00000000..4dc90c4b --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/333.md @@ -0,0 +1,51 @@ + + +Right now, you have a list of lists that contains each full tweet and you know how to lowercase the words. + +To split and lower case words in all of the tweets, you can string both methods `.lower()` and `.split()` together in a list comprehension. + +``` python +# Create a list of lists containing lowercase words for each tweet +words_in_tweet = [tweet.lower().split() for tweet in all_tweets_no_urls] +words_in_tweet[:2] + +``` + +Our output will give us data that is clean and ready to use: + +``` python +[['insurancebureau', + 'hey', + 'yoohoo', + 'hey', + 'insurancebureau', + 'maybe', + 'sometime', + 'before', + 'today', + 'and', + 'everyday', + 'from', + 'now', + 'on', + 'you', + 'sh'], + ['our', + 'rulers', + 'are', + 'golfing', + 'and', + 'trail', + 'running', + 'while', + 'human', + 'civilization', + 'burns', + 'down', + 'new', + 'piece', + 'by', + 'katearonoff', + 'climate']] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/4.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/4.md new file mode 100644 index 00000000..0ca1ac13 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/4.md @@ -0,0 +1,6 @@ + + +Now we will incorporate some elementary math to enable us to display the frequencies of each hashtag and plot it as you will see later. + +To get the count of how many times each word appears in the sample, you can use the built-in `Python` library `collections`, which helps create a special type of a `Python dictionary.` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/5.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/5.md new file mode 100644 index 00000000..383d4d45 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/5.md @@ -0,0 +1,5 @@ + + +Now that we have cleaned the data (seemingly) we can plot it to show our findings! + +We will begin by using the Pandas library which you are familiar with by now to create a DataFrame. From there we will create a bar graph which will be the most visually pleasing in this instance. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/51.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/51.md new file mode 100644 index 00000000..9a808806 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/51.md @@ -0,0 +1,12 @@ + + +Based on the counter, you can create a `Pandas Dataframe` for analysis and plotting that includes only the top 15 most common words. + +``` python +clean_tweets_no_urls = pd.DataFrame(counts_no_urls.most_common(15), + columns=['words', 'count']) + +clean_tweets_no_urls.head() +``` + +This will return a Pandas DataFrame containing two columns with the words and the frequencies they appear in our items. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/52.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/52.md new file mode 100644 index 00000000..97235026 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/52.md @@ -0,0 +1,24 @@ + + +Using this `Pandas Dataframe`, you can create a horizontal bar graph of the top 15 most common words in the tweets as shown below. + +```python +fig, ax = plt.subplots(figsize=(8, 8)) + +# Plot horizontal bar graph +clean_tweets_no_urls.sort_values(by='count').plot.barh(x='words', + y='count', + ax=ax, + color="purple") + +ax.set_title("Common Words Found in Tweets (Including All Words)") + +plt.show() +``` + +These are simple commands and paramters that we have encountered before. The plot displays the frequency of all words in the tweets on climate change, after URLs have been removed. + +With that, we are now done! Below is the output of the common words found in our Tweets. + +![Imgur](https://i.imgur.com/GloG9zm.png) + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md new file mode 100644 index 00000000..8a614c06 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md @@ -0,0 +1,11 @@ + + +For this lab we will utilize the skills you've gained working with APIs to visualize tweets using the **tweepy** Twitter API. + +The idea is simple, given a hashtag, the top 15 words pertaining to that tweet are displayed and plotted. + +Here are some examples of what we will be aiming to accomplish at the end of this Lab: + +![sample image](https://i.imgur.com/TpBec4E.png) + + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/11.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/11.md new file mode 100644 index 00000000..f3a5f03b --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/11.md @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/111.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/111.md new file mode 100644 index 00000000..80112577 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/111.md @@ -0,0 +1,12 @@ + + +If you're on Anaconda installing the Tweepy API is simple, just type the following: + +``` python +conda install tweepy +``` + +After installing the API you will also have to create a developer account with Twitter in order to access the API, this process is quick and straightforward. Just click [this](https://developer.twitter.com/en/apply-for-access.html) link to get started. + + + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/112.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/112.md new file mode 100644 index 00000000..7f14cc6e --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/112.md @@ -0,0 +1,30 @@ + + +The following packages will need to be installed in order to complete the necessary functions of the lab. By now you are already familiar with loading Python packages thanks to your previous labs. + +``` python +import os +import pandas as pd +import matplotlib.pyplot as plt +import seaborn as sns +import itertools +import collections + +import tweepy as tw +import nltk +from nltk.corpus import stopwords +import re +import networkx + +import warnings + +import warnings +warnings.filterwarnings("ignore") + +sns.set(font_scale=1.5) +sns.set_style("whitegrid") +``` + +As we progress thourgh the lab you will see how all these packages play a key role in developing our program. + + \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/12.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/12.md new file mode 100644 index 00000000..62065a92 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/12.md @@ -0,0 +1,9 @@ + + +In order to complete the various functions and methods we will perform, we need to login to twitter through our program. + +To complete this we need to go through 3 simple steps: + +1. Define your search keys +2. Create the access token to login +3. Finally, accessing the API \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/121.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/121.md new file mode 100644 index 00000000..a51a01ac --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/121.md @@ -0,0 +1,9 @@ + + +Defining the keys to login is simple, the information you need is all provided when you're developer account is created. Type the following to store it in a variable + +``` python +consumer_key= 'yourkeyhere' +consumer_secret= 'yourkeyhere' +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/122.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/122.md new file mode 100644 index 00000000..f60cd59b --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/122.md @@ -0,0 +1,18 @@ + + +Now we must create our access token, this is a key step to complete the login process. + +First, store the token values in a variable: + +``` python +access_token= 'yourkeyhere' +access_token_secret= 'yourkeyhere' +``` + +Second, use the OAuthHandler() and set_access_token() methods to create the instance that will allow login. + +``` python +auth = tw.OAuthHandler(consumer_key, consumer_secret) +auth.set_access_token(access_token, access_token_secret) +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/123.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/123.md new file mode 100644 index 00000000..64d068fd --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/123.md @@ -0,0 +1,9 @@ + + +Now that we have created our access token we can finally access the API, this can be done in a simple line. + +``` python +api = tw.API(auth, wait_on_rate_limit=True) + +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md new file mode 100644 index 00000000..634bf885 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md @@ -0,0 +1,5 @@ + + +Now that we've authenticated we're ready to search for tweets. Let's start by searching for tweets that contain **#climatechange**. + +![sample image](https://www.diggitmagazine.com/sites/default/files/styles/inline_image/public/Climate%20change%20photo_1.jpg?itok=2BfiKsqU) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/21.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/21.md new file mode 100644 index 00000000..e8156afc --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/21.md @@ -0,0 +1,11 @@ + + +In order to search for tweets under our desired hashtag, we will use the -filter method to find tweets under the climate change hashtag. + +In order to accomplish we write the following: + +``` python +search_term = "#climate+change -filter:retweets" +``` + +Here we are telling the **tweepy** API to filter for recent tweets containg the climate change hashtag \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/22.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/22.md new file mode 100644 index 00000000..3cd01ff2 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/22.md @@ -0,0 +1,3 @@ + + +Now that we've found the recent tweets containg the hashtags that we will eventually analyze, we need to store the tweets in an organized manner for analysis. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/221.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/221.md new file mode 100644 index 00000000..6175be94 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/221.md @@ -0,0 +1,15 @@ + + +For our analysis we need an accurate sample size for credible findings. We will grab 1,000 tweets under the climate change hashtag for our analysis. + +To accomplish this we will use the Cursor method to iterate through the tweets, you may remember seeing this method from a previous lab. + +``` python +tweets = tw.Cursor(api.search, + q=search_term, + lang="en", + since='2018-11-01').items(1000) +``` + +Using the Cursor method tell the iterator to search through the api, with the climate change hashtag, in english. There will be 1000 items in this iteration from tweets tweeted since Novemeber 1st 2018. + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/222.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/222.md new file mode 100644 index 00000000..87dc80d7 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/222.md @@ -0,0 +1,22 @@ + + +Now we can use list comprehension to iterate through our recently found items in a list. + +``` python +all_tweets = [tweet.text for tweet in tweets] +``` + +Here's yet another example of when list comprehension comes in handy. Especially in data analysis. + +Now let's see the output we get... + +``` python +all_tweets[:5] +# Below is the output of the first 5 results +['@InsuranceBureau Hey! Yoohoo! Hey! @InsuranceBureau! \nMaybe sometime before today, and everyday from now on, you sh… https://t.co/sWc2XT1DO8', + 'Our rulers are golfing and trail running while human civilization burns down. \n\nNew piece by @KateAronoff. #climate… https://t.co/R6HZ78oK67', + '"These findings lend themselves to a somewhat controversial idea: that we might be able to manipulate these marine… https://t.co/71w3y6fWfA', + 'Information based on proven data about #climate change and how this affects #waterAvailability is so important! Tha… https://t.co/YDe1k1sJKj', + 'Here’s what @EmoryUniversity is doing to tackle #climate change. You can get involved by visiting… https://t.co/eQsGGsob1J'] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/3.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/3.md new file mode 100644 index 00000000..68392164 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/3.md @@ -0,0 +1,5 @@ + + +As you saw from the output of our lists there are links to the tweets. While this may be nice to track the source of the tweets it will be a hinderance when parsing through the list for analysis. + +We will use regular expressions to accomplish the data cleaning. Throughout the previous labs you have gone through you may by now know that cleaning data is the longest portion of analysis projects. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/311.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/311.md new file mode 100644 index 00000000..1602b646 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/311.md @@ -0,0 +1,11 @@ + + +You may remember seeing ```import re``` while we were loading our packages earlier. Re stands for ```regular expressions```. Regular expressions are a special syntax that is used to identify patterns in a string. + +While this lesson will not cover regular expressions, it is helpful to understand that this syntax below: + +``` +([^0-9A-Za-z \t])|(\w+:\/\/\S+) +``` + +Tells the search to find all strings that look like a URL, and replace it with nothing – `""`. It also removes other punctionation including hashtags - `#`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/312.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/312.md new file mode 100644 index 00000000..e7ed3ba9 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/312.md @@ -0,0 +1,10 @@ + + +`re.sub` allows you to substitute a selection of characters defined using a regular expression, with something else. + +In the function defined below, this line takes the text in each tweet and replaces the URL with nothing: + +``` python +re.sub("([^0-9A-Za-z \t])|(\w+:\/\/\S+)", "", tweet +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/313.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/313.md new file mode 100644 index 00000000..9ad6e696 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/313.md @@ -0,0 +1,15 @@ + + +Using the re.sub method we just looked at we can create a function that removes urls from the items of our list. + +```python +def remove_url(txt): + return " ".join(re.sub("([^0-9A-Za-z \t])|(\w+:\/\/\S+)", "", txt).split()) +``` + +This is a simple function that accomplishes quiet a lot. We replace URLs found ina. text string with nothing. + +The parameters that the function takes in is a text string which we'd like to parse and remove urls from. The function returns the same txt string with url's removed. + + + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/32.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/32.md new file mode 100644 index 00000000..61642fe5 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/32.md @@ -0,0 +1,21 @@ + + +Now that we have finished removing urls from our tweets we can add them to a list for analysis. + +Again, we will use list comprehension to accomplish this task: + +``` python +all_tweets_no_urls = [remove_url(tweet) for tweet in all_tweets] +all_tweets_no_urls[:5] +``` + +Displaying the output of our first 5 elements of the list we see a much cleaner result: + +```python +['InsuranceBureau Hey Yoohoo Hey InsuranceBureau Maybe sometime before today and everyday from now on you sh', + 'Our rulers are golfing and trail running while human civilization burns down New piece by KateAronoff climate', + 'These findings lend themselves to a somewhat controversial idea that we might be able to manipulate these marine', + 'Information based on proven data about climate change and how this affects waterAvailability is so important Tha', + 'Heres what EmoryUniversity is doing to tackle climate change You can get involved by visiting'] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/33.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/33.md new file mode 100644 index 00000000..ff6ab3fc --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/33.md @@ -0,0 +1,15 @@ + + +Another challenge we will address is capitalization which becomes a challenge with data analysis for text data. If you are trying to create a list of unique words in your tweets, words with capitalization will be different from words that are all lowercase. + +Here's an example: + +```python +# Note how capitalization impacts unique returned values +ex_list = ["Dog", "dog", "dog", "cat", "cat", ","] + +# Get unique elements in the list +set(ex_list) +{',', 'Dog', 'cat', 'dog'} +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/331.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/331.md new file mode 100644 index 00000000..6b42bcc0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/331.md @@ -0,0 +1,16 @@ + + +To begin to remedy this issue we can make each word lowercase using the string method `.lower()`. In the code below, this method is applied using a list comprehension. + +```python +# Note how capitalization impacts unique returned values +words_list = ["Dog", "dog", "dog", "cat", "cat", ","] + +# Make all elements in the list lowercase +lower_case = [word.lower() for word in words_list] + +# Get all elements in the list +lower_case +['dog', 'dog', 'dog', 'cat', 'cat', ','] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/332.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/332.md new file mode 100644 index 00000000..02802ae3 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/332.md @@ -0,0 +1,10 @@ + + +Now all of the words in your list are lowercase. You can again use `set()` function to return only unique words. + +```python +# Now you have only unique words +set(lower_case) +{',', 'cat', 'dog'} +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/333.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/333.md new file mode 100644 index 00000000..4dc90c4b --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/333.md @@ -0,0 +1,51 @@ + + +Right now, you have a list of lists that contains each full tweet and you know how to lowercase the words. + +To split and lower case words in all of the tweets, you can string both methods `.lower()` and `.split()` together in a list comprehension. + +``` python +# Create a list of lists containing lowercase words for each tweet +words_in_tweet = [tweet.lower().split() for tweet in all_tweets_no_urls] +words_in_tweet[:2] + +``` + +Our output will give us data that is clean and ready to use: + +``` python +[['insurancebureau', + 'hey', + 'yoohoo', + 'hey', + 'insurancebureau', + 'maybe', + 'sometime', + 'before', + 'today', + 'and', + 'everyday', + 'from', + 'now', + 'on', + 'you', + 'sh'], + ['our', + 'rulers', + 'are', + 'golfing', + 'and', + 'trail', + 'running', + 'while', + 'human', + 'civilization', + 'burns', + 'down', + 'new', + 'piece', + 'by', + 'katearonoff', + 'climate']] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md new file mode 100644 index 00000000..c1dcde20 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md @@ -0,0 +1,5 @@ + + +Now we will incorporate some elementary math to enable us to display the frequencies of each word and plot it as youw will see later + +To get the count of how many times each word appears in the sample, you can use the built-in `Python` library `collections`, which helps create a special type of a `Python dictonary.` \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/41.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/41.md new file mode 100644 index 00000000..868d3546 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/41.md @@ -0,0 +1,31 @@ + + +To begin, flatten your list, so that all words across the tweets are in one list. Note that you could flatten your list with another list comprehension like this: all_words = [item for sublist in tweets_nsw for item in sublist] + +While the list comprehension skill we have acquired works in this case we can use the itertools library to flatten the list as follows: + +``` python +# List of all words across tweets +all_words_no_urls = list(itertools.chain(*words_in_tweet)) + +# Create counter +counts_no_urls = collections.Counter(all_words_no_urls) + +counts_no_urls.most_common(15) +[('climate', 865), + ('change', 667), + ('the', 547), + ('to', 446), + ('of', 252), + ('is', 239), + ('a', 233), + ('and', 226), + ('in', 203), + ('climatechange', 197), + ('on', 176), + ('for', 134), + ('are', 101), + ('we', 93), + ('about', 75)] +``` + diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/5.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/5.md new file mode 100644 index 00000000..90c001e9 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/5.md @@ -0,0 +1,5 @@ + + +Now that we have cleaned the data (seemingly) we can plot it to show our findings! + +We will begin by using the Pandas library which you are familiar with by now to create a DataFrame. From there we will create a bar graph which will be the most visually pleasing in this instance. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/51.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/51.md new file mode 100644 index 00000000..9a808806 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/51.md @@ -0,0 +1,12 @@ + + +Based on the counter, you can create a `Pandas Dataframe` for analysis and plotting that includes only the top 15 most common words. + +``` python +clean_tweets_no_urls = pd.DataFrame(counts_no_urls.most_common(15), + columns=['words', 'count']) + +clean_tweets_no_urls.head() +``` + +This will return a Pandas DataFrame containing two columns with the words and the frequencies they appear in our items. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/52.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/52.md new file mode 100644 index 00000000..97235026 --- /dev/null +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/52.md @@ -0,0 +1,24 @@ + + +Using this `Pandas Dataframe`, you can create a horizontal bar graph of the top 15 most common words in the tweets as shown below. + +```python +fig, ax = plt.subplots(figsize=(8, 8)) + +# Plot horizontal bar graph +clean_tweets_no_urls.sort_values(by='count').plot.barh(x='words', + y='count', + ax=ax, + color="purple") + +ax.set_title("Common Words Found in Tweets (Including All Words)") + +plt.show() +``` + +These are simple commands and paramters that we have encountered before. The plot displays the frequency of all words in the tweets on climate change, after URLs have been removed. + +With that, we are now done! Below is the output of the common words found in our Tweets. + +![Imgur](https://i.imgur.com/GloG9zm.png) + From 3d2d3794defb1cff2e3f48430a438d0d1dc727c1 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 13 Feb 2020 11:48:22 -0800 Subject: [PATCH 03/23] Week 3 Labs --- .../Week 3/Airline Sentiment Analysis/1.md | 14 +++++++++ .../Week 3/Airline Sentiment Analysis/11.md | 5 ++++ .../Week 3/Airline Sentiment Analysis/111.md | 6 ++++ .../Week 3/Airline Sentiment Analysis/112.md | 6 ++++ .../Week 3/Airline Sentiment Analysis/113.md | 5 ++++ .../Week 3/Airline Sentiment Analysis/12.md | 12 ++++++++ .../Week 3/Airline Sentiment Analysis/121.md | 6 ++++ .../Week 3/Airline Sentiment Analysis/122.md | 6 ++++ .../Week 3/Airline Sentiment Analysis/123.md | 10 +++++++ .../Week 3/Airline Sentiment Analysis/2.md | 5 ++++ .../Week 3/Airline Sentiment Analysis/21.md | 8 +++++ .../Week 3/Airline Sentiment Analysis/211.md | 11 +++++++ .../Week 3/Airline Sentiment Analysis/212.md | 16 ++++++++++ .../Week 3/Airline Sentiment Analysis/213.md | 8 +++++ .../Week 3/Airline Sentiment Analysis/3.md | 4 +++ .../Week 3/Airline Sentiment Analysis/31.md | 10 +++++++ .../Week 3/Airline Sentiment Analysis/311.md | 20 +++++++++++++ .../Week 3/Airline Sentiment Analysis/312.md | 17 +++++++++++ .../Week 3/Airline Sentiment Analysis/32.md | 15 ++++++++++ .../Week 3/Airline Sentiment Analysis/321.md | 30 +++++++++++++++++++ .../Week 3/Airline Sentiment Analysis/4.md | 7 +++++ .../Week 3/Airline Sentiment Analysis/5.md | 12 ++++++++ .../Week 3/Airline Sentiment Analysis/51.md | 12 ++++++++ .../Week 3/Airline Sentiment Analysis/52.md | 22 ++++++++++++++ .../Week 3/Airline Sentiment Analysis/53.md | 5 ++++ .../Week 3/Airline Sentiment Analysis/6.md | 3 ++ .../Week 3/Democratic Debate Sentiment/1.md | 14 +++++++++ .../Week 3/Democratic Debate Sentiment/11.md | 5 ++++ .../Week 3/Democratic Debate Sentiment/111.md | 6 ++++ .../Week 3/Democratic Debate Sentiment/112.md | 6 ++++ .../Week 3/Democratic Debate Sentiment/113.md | 5 ++++ .../Week 3/Democratic Debate Sentiment/12.md | 12 ++++++++ .../Week 3/Democratic Debate Sentiment/121.md | 6 ++++ .../Week 3/Democratic Debate Sentiment/122.md | 6 ++++ .../Week 3/Democratic Debate Sentiment/123.md | 10 +++++++ .../Week 3/Democratic Debate Sentiment/2.md | 5 ++++ .../Week 3/Democratic Debate Sentiment/21.md | 8 +++++ .../Week 3/Democratic Debate Sentiment/211.md | 11 +++++++ .../Week 3/Democratic Debate Sentiment/212.md | 16 ++++++++++ .../Week 3/Democratic Debate Sentiment/213.md | 8 +++++ .../Week 3/Democratic Debate Sentiment/3.md | 4 +++ .../Week 3/Democratic Debate Sentiment/31.md | 12 ++++++++ .../Week 3/Democratic Debate Sentiment/311.md | 20 +++++++++++++ .../Week 3/Democratic Debate Sentiment/312.md | 17 +++++++++++ .../Week 3/Democratic Debate Sentiment/32.md | 15 ++++++++++ .../Week 3/Democratic Debate Sentiment/321.md | 30 +++++++++++++++++++ .../Week 3/Democratic Debate Sentiment/33.md | 3 ++ .../Week 3/Democratic Debate Sentiment/331.md | 14 +++++++++ .../Week 3/Democratic Debate Sentiment/4.md | 17 +++++++++++ .../Week 3/Democratic Debate Sentiment/41.md | 12 ++++++++ .../Week 3/Democratic Debate Sentiment/42.md | 22 ++++++++++++++ .../Week 3/Democratic Debate Sentiment/43.md | 5 ++++ .../Week 3/Democratic Debate Sentiment/5.md | 3 ++ 53 files changed, 567 insertions(+) create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/12.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/122.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/312.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/321.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/5.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/51.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/52.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/53.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/6.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/111.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/21.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/211.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/212.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/213.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/3.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/31.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/311.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/312.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/32.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/321.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/33.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/331.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/4.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/41.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/42.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/43.md create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/5.md diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md new file mode 100644 index 00000000..00aef389 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md @@ -0,0 +1,14 @@ +# Introduction + +For this lab, we will be conducting sentiment analysis on specific US airlines. To do this, we'll be gathering tweets referencing airlines using Twitter's API as well as the `tweepy` and `TextBlob` packages to determine whether generated tweets have a positive, neutral or negative attitude towards the airline in question. Then we'll graph that information, both in the form of a bar and line graph. + +Twitter presence is an important point of emphasis for companies. Twitter users can quickly form a positive or negative opinion of company, depending on what users are tweeting pertaining to companies. Companies perform sentiment analysis frequently to gauge what Twitter's opinion of their company is, and what steps they can take to ensure a positive Twitter presence for their company. We'll conduct an elementary sentiment analysis that companies may conduct for this lab, this is an example of what you should be making by the end: + +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/AirlineSentimentExample.png) + + + +To start off, you'll need to make a new Twitter app and get four credentials for future use: consumer key, consumer token, access token and access secret token. + +Paste those credentials into the appropriate area in your starter code. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md new file mode 100644 index 00000000..28c6697a --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md @@ -0,0 +1,5 @@ + + +The Twitter developer application process starts here, please complete the form. + +![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md new file mode 100644 index 00000000..6e78cbed --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md @@ -0,0 +1,6 @@ + + +Proceed to Twitter Developer [here](https://developer.twitter.com/en/apps). Implementing sign-in with Twitter requires a Twitter developer account, so click “Apply”. + + + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md new file mode 100644 index 00000000..20e2f2c8 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md @@ -0,0 +1,6 @@ + + +The Twitter developer application process starts here, please complete the form. + +![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md new file mode 100644 index 00000000..6f158b95 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md @@ -0,0 +1,5 @@ + + +After finishing your application, confirm your email and your account should be processed and reviewed swiftly. + +![img](https://lh4.googleusercontent.com/8BKvmctSfLQEKERSZIc9_3jKl7lnpkRJO3736TBuIkfwBzZhkZMmPL8hUnNjrCf27SqX1iZaHOv1RBrNfB2V1990cl9z35ojA-RjoDnN0vgn5XWuDhwMjpbbhHLj5J1qcuq4M2KSC4g) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/12.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/12.md new file mode 100644 index 00000000..11b31eef --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/12.md @@ -0,0 +1,12 @@ + + +When you have finished configuring your account, head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: + +![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. + +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) + +![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) + +There is also an area to generate an access token and access secret token, please generate them and keep track of those as well. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md new file mode 100644 index 00000000..07a09b03 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md @@ -0,0 +1,6 @@ + + +Head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: + +![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/122.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/122.md new file mode 100644 index 00000000..3f94fc25 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/122.md @@ -0,0 +1,6 @@ + + +In the creation of your app, fill out all the required information for your app details. For the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. + +![img](https://lh6.googleusercontent.com/wCWo0frQNm2aPD3Fv30kMC90DQDk880eGb1KTGrL5I7dOjis95GoVBI2zJJ3tacIz-0ux9HFpgAYeB4Ym_LC2OAPabCMRzGeiRtnVRUbKAqn_PdGyMLunDhZCo_h-4XIysnYivjUwnI) + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md new file mode 100644 index 00000000..1fef04ca --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md @@ -0,0 +1,10 @@ + + +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) + +![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) + + + +Below the consumer API keys, there is also an area to generate an access token and access secret token, please generate them and keep track of those as well. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md new file mode 100644 index 00000000..1d6ea5d0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md @@ -0,0 +1,5 @@ +# Authentication + +Paste your keys and tokens in the allocated space. Then configure OAuth authentication with your consumer key and secret, set your access tokens and create a API object in `tweepy` to fetch tweets. + +Bear in mind we will be using the `us_search` dictionary for the rest of this lab. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md new file mode 100644 index 00000000..77cae357 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md @@ -0,0 +1,8 @@ + + +Paste your keys and tokens in the allocated space. You'll want to authenticate in three steps: + +1. Configure OAuth authentication with your consumer key and secret with the `OAuthHandler(consumer_key, consumer_secret)` call. This should create an `auth` object +2. Set your access tokens with `auth.set_access_token()`. +3. Create a API object in `tweepy` to fetch tweets: `tweepy.API(auth, wait_on_rate_limit=True)` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md new file mode 100644 index 00000000..e2315f0b --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md @@ -0,0 +1,11 @@ + + +Remember all those credentials you generated? Paste them appropriately in the starter code. + +```python +consumer_key = 'xxx' +consumer_secret = 'xxx' +access_token = 'xxx' +access_token_secret = 'xxx' +``` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md new file mode 100644 index 00000000..0d30563d --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md @@ -0,0 +1,16 @@ + + +We are now going to authenticate using our app credentials. Please look at the next two lines of code: + +```python +auth = OAuthHandler(consumer_key, consumer_secret) +``` + +This line generates an authentication object using our consumer key and secret. + +```python +auth.set_access_token(access_token, access_token_secret) +``` + +This line enables access to our authentication object with our access token and access secret token. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md new file mode 100644 index 00000000..e7466b3c --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md @@ -0,0 +1,8 @@ + + +The `tweepy` package allows us to very easily use Twitter's API within a Python environment. The line below will give us an API object that will allow us to fetch tweets. + +```python +api = tw.API(auth, wait_on_rate_limit=True) +``` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md new file mode 100644 index 00000000..5dbfd358 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md @@ -0,0 +1,4 @@ +# Producing Dataframes + +First, we'll have to complete the function `produce_dataframe()`. Please reference the description in the starter code. Bear in mind we provide what will be passed into the `search_query` parameter for you, and you are not allowed to change any function definition or given code. By the end, you should have a data frame with just the date and sentiment of each tweet found. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md new file mode 100644 index 00000000..4015328d --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md @@ -0,0 +1,10 @@ + + + + +Our end result is going to be a dataframe with columns for the date of tweet and sentiment behind the tweet. This dataframe will be used to set up the graph later. + +Firstly, make a empty dataframe `df` with 2 empty columns, and set the columns attribute to be `['date', 'sentiment']`. + +For your search query, use the `Cursor` object from `tweepy` to generate n number of tweets including each query. (n corresponds to the parameter `num_tweets` in this case.) + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md new file mode 100644 index 00000000..4e41893f --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md @@ -0,0 +1,20 @@ + + + + +We want a dataframe with the following structure: + + + +| | Airline_0 | Airline_1 | ... | +| -------- | --------------- | --------------- | ---- | +| positive | 321 | 23 | ... | +| neutral | 76 | 32 | ... | +| negative | \# example data | \# example data | ... | + +Our dataframe `df` will do the trick: + +``` +df = pd.DataFrame([], index=['positive', 'neutral', 'negative']) +``` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/312.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/312.md new file mode 100644 index 00000000..f32b7d59 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/312.md @@ -0,0 +1,17 @@ + + +The `Cursor` in `tweepy` will allow us to find `num_tweets` tweets given a search query `val`. + +```python +# Collect tweets +tweets = tw.Cursor(api.search, q=val, lang="en", since=date_since).items(num_tweets) +``` + +Because we are given a dictionary with search queries, we want to iterate through this dictionary and call the above line for each search query (each query corresponds to one airline): + +```python +for key, val in search_dict.items(): + # Collect tweets + tweets = tw.Cursor(api.search, q=val, lang="en", since=date_since).items(num_tweets) +``` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md new file mode 100644 index 00000000..95d57622 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md @@ -0,0 +1,15 @@ + + + + +In our `Cursor` object is a list of tweets with our search query. + +Iterate through this cursor object and find whether its sentiment is positive, neutral or negative. + +* You'll have to use `TextBlob` as well as the `sentiment.polarity` attribute. + +Keep track of a list that will contain the sentiment ratings 'positive', 'neutral' or 'negative'. For each tweet, make sure you append the tweet's sentiment. + +When done iterating through the tweets, index the dataframe so that the sentiment data shows up in your dataframe. + +The function should return `df`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/321.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/321.md new file mode 100644 index 00000000..6a27d795 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/321.md @@ -0,0 +1,30 @@ + + + + +For each tweet object in the cursor, we can use the `.text` attribute to get the text of the tweet itself. Then for each text, we make a `TextBlob` object out of that text. + +From there, simply check the values of the `.sentiment.polarity` attribute. Positive polarity indicates positive sentiment, zero polarity indicates neutral sentiment and neutral polarity indicates negative sentiment. + +We keep track of positive, neutral and negative tweets with counter variables. At the end, we add the acquired sentiment data to the dataframe. + +Return `df` at the end. + +```python +for key, val in search_dict.items(): + # ... + + positive = 0 + neutral = 0 + negative = 0 + for t in tweets: + analysis = TextBlob(t.text) + if analysis.sentiment.polarity > 0: + positive += 1 + elif analysis.sentiment.polarity == 0: + neutral += 1 + else: + negative += 1 + df[key] = [positive, neutral, negative] +return df +``` \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md new file mode 100644 index 00000000..ddaa8d8b --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md @@ -0,0 +1,7 @@ +# Set-up Dataframes for Graph + +Now that we have our raw dataframe of dates and sentiments, we need to calculate the total tweets and the percentage of positive/neutral/negative tweets per day. + +Set up *one* dataframe that contains all of that data. This is what your dataframe should look like: + +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/Airline_DF.PNG) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/5.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/5.md new file mode 100644 index 00000000..cdcbc47b --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/5.md @@ -0,0 +1,12 @@ +# Graphing + +Now that we have our dataframe with the number of positive, neutral, and negative tweets for each candidate, it's time to graph! + +We'll be graphing a bar graph representing the total number of tweets per day for + +Inside of the function `produce_graph(df, keys)`, create a bar graph, with each bar labelled with an appropriate date for the tick. Then on top of that bar graph, create a line graph with three lines for the positive, neutral, and negative sentiment on *each day*. + +Data presentation is everything - without putting your due diligence into your presentation, less people will read your analytics! So make sure your graph is properly titled, with a legend, x-axes, y-axes, and x and y labels. Don't forget to have 2 y-axes! (one for your bar graph and one for your line graph). As a reminder this is what your graph should look like: + +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/AirlineSentimentExample.png) + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/51.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/51.md new file mode 100644 index 00000000..49a59138 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/51.md @@ -0,0 +1,12 @@ +# Setting Up Bars + +Remember that even though this is a stacked bar graph, you are still essentially graphing numbers on a bar graph, with the caveat that the bars are on top of each other, and so the location of the bars needs to be controlled. + +To make your bars on your graph, there are two steps you need to take: + +* Locate the positive, neutral and negative lists in your data frame. That is the data you will be graphing. +* Use `plt.bar` to graph bar graphs. + * Start off with just graphing the positive bars and making sure those work. + * Then graph the neutral bars, setting the **bottom** to be the positive bars. + * Do the same for negative bars. + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/52.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/52.md new file mode 100644 index 00000000..65ab6ddc --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/52.md @@ -0,0 +1,22 @@ +# Making Graph Pretty + +Now that your bars are set up, your graph most likely looks unorganized. To organize our graph better, we can set margins to the x ticks to space them out. Because the specifics of how to space out x tick labels can get quite complicated and out of the scope of this bootcamp, I'll provide a chunk of code for you here: + +```python +# space out x ticks and give margins +plt.gca().margins(x=0) +plt.gcf().canvas.draw() +tl = plt.gca().get_xticklabels() +maxsize = max([t.get_window_extent().width for t in tl]) +m = 0.1 # inch margin +s = maxsize/plt.gcf().dpi*7+2*m +margin = m/plt.gcf().get_size_inches()[0] + +plt.gcf().subplots_adjust(left=margin, right=1.-margin) +plt.gcf().set_size_inches(s, plt.gcf().get_size_inches()[1]) +``` + +This code should space out your x ticks and set margins. + +Don't forget a title (`plt.title`) and a legend (`plt.legend`)! + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/53.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/53.md new file mode 100644 index 00000000..224384de --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/53.md @@ -0,0 +1,5 @@ +# Text Labels + +To add text labels, we'll have to iterate through all the bars and append an appropriate label to each one. So firstly, set up a list called `labels`, that has all the positive, neutral and negative data *in one list*. + +We can use `ax.patches` to find a list of all the bars currently in the graph. We can then `zip` the labels and patches together, iterate through that, and for each patch use `ax.text` to attribute a label to each bar. Make sure you have an appropriate location when using `ax.text`! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/6.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/6.md new file mode 100644 index 00000000..45f890d6 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/6.md @@ -0,0 +1,3 @@ +# `main()` + +It's time to put all of our functions together into a program! Call `produce_dataframe()` and `produce_graph` inside of your main() function with the proper parameters, and run your main() to see your graphs made! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md new file mode 100644 index 00000000..f91ec835 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md @@ -0,0 +1,14 @@ +# Introduction + +With the wealth of information at our disposal, American politics have increasingly become a game of misinformation and narrative twisting. To win elections, often times it doesn't matter what political candidates actually do or say, but how candidates can control the narrative surrounding their campaigns, and what the American people think of their candidates. + +Twitter reactions are a valuable source of political opinions from regular Americans, because anyone can tweet their honest feelings about political candidates. Using sentiment analysis on Americans' tweets can give us genuine insight on the sentiment behind every candidate in the race, outside of media spin or campaign biases. For this lab, we'll dive into the tweets during and after the 7th Democratic Debate to gauge how average Americans perceive political candidates, and graph our results in a stacked bar graph! Here is what the result should look like: + +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/6thDemDebateGraph.png) + +To do this, we'll be gathering tweets referencing political candidates using Twitter's API as well as the `tweepy` and `TextBlob`packages to determine whether generated tweets have a positive, neutral or negative attitude towards the airlines. + +Proceed to Twitter Developer [here](https://developer.twitter.com/en/apps), and you'll need to make a new Twitter app and get four credentials for future use: consumer key, consumer token, access token and access secret token. + +Paste those credentials into the appropriate area in your starter code. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md new file mode 100644 index 00000000..28c6697a --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md @@ -0,0 +1,5 @@ + + +The Twitter developer application process starts here, please complete the form. + +![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/111.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/111.md new file mode 100644 index 00000000..6e78cbed --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/111.md @@ -0,0 +1,6 @@ + + +Proceed to Twitter Developer [here](https://developer.twitter.com/en/apps). Implementing sign-in with Twitter requires a Twitter developer account, so click “Apply”. + + + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md new file mode 100644 index 00000000..20e2f2c8 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md @@ -0,0 +1,6 @@ + + +The Twitter developer application process starts here, please complete the form. + +![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md new file mode 100644 index 00000000..6f158b95 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md @@ -0,0 +1,5 @@ + + +After finishing your application, confirm your email and your account should be processed and reviewed swiftly. + +![img](https://lh4.googleusercontent.com/8BKvmctSfLQEKERSZIc9_3jKl7lnpkRJO3736TBuIkfwBzZhkZMmPL8hUnNjrCf27SqX1iZaHOv1RBrNfB2V1990cl9z35ojA-RjoDnN0vgn5XWuDhwMjpbbhHLj5J1qcuq4M2KSC4g) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md new file mode 100644 index 00000000..11b31eef --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md @@ -0,0 +1,12 @@ + + +When you have finished configuring your account, head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: + +![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. + +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) + +![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) + +There is also an area to generate an access token and access secret token, please generate them and keep track of those as well. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md new file mode 100644 index 00000000..07a09b03 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md @@ -0,0 +1,6 @@ + + +Head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: + +![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md new file mode 100644 index 00000000..3f94fc25 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md @@ -0,0 +1,6 @@ + + +In the creation of your app, fill out all the required information for your app details. For the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. + +![img](https://lh6.googleusercontent.com/wCWo0frQNm2aPD3Fv30kMC90DQDk880eGb1KTGrL5I7dOjis95GoVBI2zJJ3tacIz-0ux9HFpgAYeB4Ym_LC2OAPabCMRzGeiRtnVRUbKAqn_PdGyMLunDhZCo_h-4XIysnYivjUwnI) + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md new file mode 100644 index 00000000..1fef04ca --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md @@ -0,0 +1,10 @@ + + +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) + +![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) + + + +Below the consumer API keys, there is also an area to generate an access token and access secret token, please generate them and keep track of those as well. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md new file mode 100644 index 00000000..7811e37d --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md @@ -0,0 +1,5 @@ +# Authentication + +Paste your keys and tokens in the allocated space. Then configure OAuth authentication with your consumer key and secret, set your access tokens and create a API object in `tweepy` to fetch tweets. + +Bear in mind we will be using the `dem_search` dictionary for the rest of this lab. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/21.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/21.md new file mode 100644 index 00000000..77cae357 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/21.md @@ -0,0 +1,8 @@ + + +Paste your keys and tokens in the allocated space. You'll want to authenticate in three steps: + +1. Configure OAuth authentication with your consumer key and secret with the `OAuthHandler(consumer_key, consumer_secret)` call. This should create an `auth` object +2. Set your access tokens with `auth.set_access_token()`. +3. Create a API object in `tweepy` to fetch tweets: `tweepy.API(auth, wait_on_rate_limit=True)` + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/211.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/211.md new file mode 100644 index 00000000..e2315f0b --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/211.md @@ -0,0 +1,11 @@ + + +Remember all those credentials you generated? Paste them appropriately in the starter code. + +```python +consumer_key = 'xxx' +consumer_secret = 'xxx' +access_token = 'xxx' +access_token_secret = 'xxx' +``` + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/212.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/212.md new file mode 100644 index 00000000..0d30563d --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/212.md @@ -0,0 +1,16 @@ + + +We are now going to authenticate using our app credentials. Please look at the next two lines of code: + +```python +auth = OAuthHandler(consumer_key, consumer_secret) +``` + +This line generates an authentication object using our consumer key and secret. + +```python +auth.set_access_token(access_token, access_token_secret) +``` + +This line enables access to our authentication object with our access token and access secret token. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/213.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/213.md new file mode 100644 index 00000000..e7466b3c --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/213.md @@ -0,0 +1,8 @@ + + +The `tweepy` package allows us to very easily use Twitter's API within a Python environment. The line below will give us an API object that will allow us to fetch tweets. + +```python +api = tw.API(auth, wait_on_rate_limit=True) +``` + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/3.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/3.md new file mode 100644 index 00000000..5e059159 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/3.md @@ -0,0 +1,4 @@ +# Producing Dataframes + +First, we'll have to complete the function `produce_dataframe()`. Please reference the description in the starter code. Bear in mind we provide what will be passed into the `search_dict` parameter for you, and you are not allowed to change any function definition or given code. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/31.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/31.md new file mode 100644 index 00000000..27371b7d --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/31.md @@ -0,0 +1,12 @@ + + + + +Our end result is going to be a dataframe indexed by sentiment categories `['positive', 'neutral', 'negative']` and our columns being various airlines of a category. From this dataframe, one should be able to easily look up the number of positive/neutral/negative tweets regarding an airline. + +Firstly, make a empty dataframe `df` indexed by the array `['positive', 'neutral', 'negative']`. + +A `search_dict` simply is a dictionary with airline names mapped to appropriate search queries on Twitter. We can use `tweepy` to search for tweets including those search queries. + +For each search query, use the `Cursor` object from `tweepy` to generate n number of tweets including each query. (n corresponds to the parameter `num_tweets` in this case.) + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/311.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/311.md new file mode 100644 index 00000000..4e41893f --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/311.md @@ -0,0 +1,20 @@ + + + + +We want a dataframe with the following structure: + + + +| | Airline_0 | Airline_1 | ... | +| -------- | --------------- | --------------- | ---- | +| positive | 321 | 23 | ... | +| neutral | 76 | 32 | ... | +| negative | \# example data | \# example data | ... | + +Our dataframe `df` will do the trick: + +``` +df = pd.DataFrame([], index=['positive', 'neutral', 'negative']) +``` + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/312.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/312.md new file mode 100644 index 00000000..f32b7d59 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/312.md @@ -0,0 +1,17 @@ + + +The `Cursor` in `tweepy` will allow us to find `num_tweets` tweets given a search query `val`. + +```python +# Collect tweets +tweets = tw.Cursor(api.search, q=val, lang="en", since=date_since).items(num_tweets) +``` + +Because we are given a dictionary with search queries, we want to iterate through this dictionary and call the above line for each search query (each query corresponds to one airline): + +```python +for key, val in search_dict.items(): + # Collect tweets + tweets = tw.Cursor(api.search, q=val, lang="en", since=date_since).items(num_tweets) +``` + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/32.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/32.md new file mode 100644 index 00000000..b96fa681 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/32.md @@ -0,0 +1,15 @@ + + + + +In our `Cursor` object is a list of tweets with our search query. + +Iterate through this cursor object and find whether its sentiment is positive, neutral or negative. + +* You'll have to use `TextBlob` as well as the `sentiment.polarity` attribute. + +Keep track of a count of positive, neutral and negative tweets. + +When done iterating through the tweets, index the dataframe so that the sentiment data shows up in your dataframe. + +The function should return `df`. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/321.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/321.md new file mode 100644 index 00000000..6a27d795 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/321.md @@ -0,0 +1,30 @@ + + + + +For each tweet object in the cursor, we can use the `.text` attribute to get the text of the tweet itself. Then for each text, we make a `TextBlob` object out of that text. + +From there, simply check the values of the `.sentiment.polarity` attribute. Positive polarity indicates positive sentiment, zero polarity indicates neutral sentiment and neutral polarity indicates negative sentiment. + +We keep track of positive, neutral and negative tweets with counter variables. At the end, we add the acquired sentiment data to the dataframe. + +Return `df` at the end. + +```python +for key, val in search_dict.items(): + # ... + + positive = 0 + neutral = 0 + negative = 0 + for t in tweets: + analysis = TextBlob(t.text) + if analysis.sentiment.polarity > 0: + positive += 1 + elif analysis.sentiment.polarity == 0: + neutral += 1 + else: + negative += 1 + df[key] = [positive, neutral, negative] +return df +``` \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/33.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/33.md new file mode 100644 index 00000000..b5fc3605 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/33.md @@ -0,0 +1,3 @@ + + +Now let's fill out `init_dataframes()`. Call your method `produce_dataframe` on the defined dictionaries `low_cost_search` and `luxury_search` to produce two dataframes which consist of sentiment data on low-cost airlines and luxury airlines. Print *the entirety* of these dataframes to the Python console and return *both* of them. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/331.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/331.md new file mode 100644 index 00000000..9d87b411 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/331.md @@ -0,0 +1,14 @@ + + +To do this, call `produce_dataframe()` twice on `low_cost_search` and `luxury_search`, each with the 100 tweets as a parameter. + +Then we print the *entirety* of the dataframe using `.to_string()` and return the resulting dataframes. + +```python +def init_dataframes(): + low_cost_df = produce_dataframe(low_cost_search, 100) + luxury_cost_df = produce_dataframe(luxury_search, 100) + print(low_cost_df.to_string()) + print(luxury_cost_df.to_string()) + return low_cost_df, luxury_cost_df +``` \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/4.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/4.md new file mode 100644 index 00000000..9cb3384a --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/4.md @@ -0,0 +1,17 @@ +# Graphing + +Now that we have our dataframe with the number of positive, neutral, and negative tweets for each candidate, it's time to graph! + +Inside of the function `produce_graph(df, keys)`, create a stacked bar graph, with each bar labelled with the number of the positive/neutral/negative tweets. Data presentation is everything - without putting your due diligence into your presentation, less people will read your analytics! So make sure your graph is properly titled, with a legend, x-axes, y-axes, and x and y labels. + +Here are some formatting rules (and hints!) that were used in the graph below: + +* Width of bars is 0.40 +* The legend is placed outside the graph using `bbox_to_anchor` +* 0.1 inch margin between x-axis labels +* Think about what `matplotlib` function you would use to set up a bar graph. How would you set up bars so that the bottom of one bar is set at the same location as the top of another? +* You can set up text labels by initializing a figure `fig` with `plt.figure`, then initializing a subplot `ax` with `fig.add_subplot` and adding text labels at a location `(x, y)` with `ax.text(x, y, ...)` + +Remember that this is the result you are aiming for: + +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/6thDemDebateGraph.png) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/41.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/41.md new file mode 100644 index 00000000..49a59138 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/41.md @@ -0,0 +1,12 @@ +# Setting Up Bars + +Remember that even though this is a stacked bar graph, you are still essentially graphing numbers on a bar graph, with the caveat that the bars are on top of each other, and so the location of the bars needs to be controlled. + +To make your bars on your graph, there are two steps you need to take: + +* Locate the positive, neutral and negative lists in your data frame. That is the data you will be graphing. +* Use `plt.bar` to graph bar graphs. + * Start off with just graphing the positive bars and making sure those work. + * Then graph the neutral bars, setting the **bottom** to be the positive bars. + * Do the same for negative bars. + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/42.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/42.md new file mode 100644 index 00000000..65ab6ddc --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/42.md @@ -0,0 +1,22 @@ +# Making Graph Pretty + +Now that your bars are set up, your graph most likely looks unorganized. To organize our graph better, we can set margins to the x ticks to space them out. Because the specifics of how to space out x tick labels can get quite complicated and out of the scope of this bootcamp, I'll provide a chunk of code for you here: + +```python +# space out x ticks and give margins +plt.gca().margins(x=0) +plt.gcf().canvas.draw() +tl = plt.gca().get_xticklabels() +maxsize = max([t.get_window_extent().width for t in tl]) +m = 0.1 # inch margin +s = maxsize/plt.gcf().dpi*7+2*m +margin = m/plt.gcf().get_size_inches()[0] + +plt.gcf().subplots_adjust(left=margin, right=1.-margin) +plt.gcf().set_size_inches(s, plt.gcf().get_size_inches()[1]) +``` + +This code should space out your x ticks and set margins. + +Don't forget a title (`plt.title`) and a legend (`plt.legend`)! + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/43.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/43.md new file mode 100644 index 00000000..224384de --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/43.md @@ -0,0 +1,5 @@ +# Text Labels + +To add text labels, we'll have to iterate through all the bars and append an appropriate label to each one. So firstly, set up a list called `labels`, that has all the positive, neutral and negative data *in one list*. + +We can use `ax.patches` to find a list of all the bars currently in the graph. We can then `zip` the labels and patches together, iterate through that, and for each patch use `ax.text` to attribute a label to each bar. Make sure you have an appropriate location when using `ax.text`! \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/5.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/5.md new file mode 100644 index 00000000..45f890d6 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/5.md @@ -0,0 +1,3 @@ +# `main()` + +It's time to put all of our functions together into a program! Call `produce_dataframe()` and `produce_graph` inside of your main() function with the proper parameters, and run your main() to see your graphs made! \ No newline at end of file From 052eb7c64d03731654841a32128f0f237d27331c Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 13 Feb 2020 11:57:49 -0800 Subject: [PATCH 04/23] Week 2 Modifications --- .../labs/Week 2/Twitter Hashtag Frequency/1.md | 2 +- Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md | 6 ++++-- Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md | 2 +- Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md index 77785a76..7765475a 100644 --- a/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md +++ b/Module_Twitter_API/labs/Week 2/Twitter Hashtag Frequency/1.md @@ -2,7 +2,7 @@ For this lab we will utilize the skills you've gained working with APIs to visualize tweets using the **tweepy** Twitter API. -The idea is simple, given a topic, all hashtags with greater than 5% frequency pertaining to that topic are plotted in a pie graph. All hashtags with less than 5% frequency fall under an "Other" category. +The idea is simple, given a topic, all hashtags with greater than 5% frequency pertaining to that topic are plotted in a pie graph. All hashtags with less than 5% frequency fall under an "Other" category. Hashtags provide an efficient way of deducing how tweeters feel about the topic they are tweeting about, since Twitter users use hashtags to summarize their tweets, often with more emotion. Therefore hashtags provide a sufficient summary of the tweet - there is a lesser need to process every character and word of a tweet if the hashtags are available. diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md index 8a614c06..6b3279dc 100644 --- a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/1.md @@ -2,9 +2,11 @@ For this lab we will utilize the skills you've gained working with APIs to visualize tweets using the **tweepy** Twitter API. -The idea is simple, given a hashtag, the top 15 words pertaining to that tweet are displayed and plotted. +The idea is simple, given a hashtag, the top 15 words pertaining to that hashtag are displayed and plotted on a bar graph. -Here are some examples of what we will be aiming to accomplish at the end of this Lab: +Twitter users use hashtags to summarize their feelings and associate their tweets with a greater idea or belief. By seeing the most common words associated with a hashtag, we can gain a general sense of what people are talking about with a certain hashtag, how people feel and gain a greater grasp of what the general sentiment is around a hashtag. It's easy to get caught in our own echo chambers on social media, and analyzing the most common words across *all* tweets for a certain hashtag helps us analyze the feelings behind a hashtag in a more objective manner. + +Here is an example of what we will be aiming to accomplish at the end of this lab: ![sample image](https://i.imgur.com/TpBec4E.png) diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md index 634bf885..eed95ca1 100644 --- a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/2.md @@ -1,5 +1,5 @@ -Now that we've authenticated we're ready to search for tweets. Let's start by searching for tweets that contain **#climatechange**. +Now that we've authenticated we're ready to search for tweets. Let's start by searching for tweets that contain a hashtag of your choice, preferably a hashtag that is more thought-provoking. You can use the example **#climatechange** if you'd like. ![sample image](https://www.diggitmagazine.com/sites/default/files/styles/inline_image/public/Climate%20change%20photo_1.jpg?itok=2BfiKsqU) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md index c1dcde20..7b13d4aa 100644 --- a/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md +++ b/Module_Twitter_API/labs/Week 2/Twitter Word Frequency/4.md @@ -1,5 +1,5 @@ -Now we will incorporate some elementary math to enable us to display the frequencies of each word and plot it as youw will see later +Now we will incorporate some elementary math to enable us to display the frequencies of each word and plot it as you will see later. To get the count of how many times each word appears in the sample, you can use the built-in `Python` library `collections`, which helps create a special type of a `Python dictonary.` \ No newline at end of file From b204654385ad00b934c67f829d98b4d0641c569d Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Tue, 18 Feb 2020 16:36:07 -0800 Subject: [PATCH 05/23] Added better use cases and linked each method to CRUD still needs additonal use cases --- Node_Week_2/.DS_Store | Bin 6148 -> 8196 bytes Node_Week_2/expressworks/Part 1/0d.md | 31 +++++++++++++++++------- Node_Week_2/expressworks/Part 1/0e.md | 10 ++++---- Node_Week_2/expressworks/Part 1/0f.md | 7 +++--- Node_Week_2/expressworks/Part 1/0g.md | 5 ++-- Node_Week_2/js-best-practices/.DS_Store | Bin 0 -> 8196 bytes 6 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 Node_Week_2/js-best-practices/.DS_Store diff --git a/Node_Week_2/.DS_Store b/Node_Week_2/.DS_Store index 58fb0be4f5b8261ad4b300f3a005e547b5e76d1d..4a22cc0f7135e4a14e11e118d02db91cd83733e2 100644 GIT binary patch delta 283 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD6lbLH}hr%jz7$c**Q2SHn1=X zOy*&EEMjb7prc@DZdt3NP;G7wWSbfpPiAIqWLoG9l$R07&3AE0%E?axnK>mn&oAQN zK}V=W3RVgJf(*mpLL!s{zGjL~`?8T#|C~lR*0S2be`Te?903l}N!V!C#PJ7@VA+TL9Dn z1Ro{~3LTt$R+x`TTwrpbh?)?xfi*$)#p^y!_7~BZY%9XU2IrbFHcTw6SkWUzxAie^5lwor`&m3j|@EAJI diff --git a/Node_Week_2/expressworks/Part 1/0d.md b/Node_Week_2/expressworks/Part 1/0d.md index 47d6c420..a223bad6 100644 --- a/Node_Week_2/expressworks/Part 1/0d.md +++ b/Node_Week_2/expressworks/Part 1/0d.md @@ -1,21 +1,34 @@ -GET requests fetch data from specified resource. +GET requests retrieve data from server. It is the **Read** of the **R** in **CRUD**. + +Lets say we want to retrieve some data from a server every time someone visits the homepage of our website. We would use a **get** request with ``/home`` as the handle: ```javascript -app.get('handle', function (req, res) { - //code to perform a specified action +app.get('/home', function (req, res) { + //code to perform a specified action }) ``` -In this case, GET is fetching the the data from the handle. +Lets say that on the home page, we have some information that we would like to retreive. In the home.html file, it contains: + +```html + + +
+Favorite Movie:
+ +
+ + +``` -Often, the handle is simply `/` which is the root: +Now, when we use the **get** request, we can use data from the server to perform an action: ```javascript -app.get('/', function (req, res) { - //code to perform a specified action - res.send('got it!') -}) +app.get('/home', function (req, res) { + res.send('

Favorite Movie: ' + req.query['movie']'

'); +}) ``` +Here, \ No newline at end of file diff --git a/Node_Week_2/expressworks/Part 1/0e.md b/Node_Week_2/expressworks/Part 1/0e.md index 16a460f9..790d80ad 100644 --- a/Node_Week_2/expressworks/Part 1/0e.md +++ b/Node_Week_2/expressworks/Part 1/0e.md @@ -1,6 +1,6 @@ -The POST method can be used to send large amounts of information to a specified resource. +POST creates data in server and is the **C** in **CRUD**. To use post, first install **bodyParser** in the package file: @@ -19,12 +19,12 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); ``` -Now, we can use post like so: +Now, we can use post! Lets say we want to create some data on a server every time someone visits the homepage of our website. We would use a **post** request with ``/home`` as the handle: ```js -app.post('/', function (req, res) { // The '/'is the handler to the root route - //code to perform any specified action - res.send('posted!') +app.post('/home:id', function (req, res) { + const movie = req.params.id; + res.send('posted!') }) ``` diff --git a/Node_Week_2/expressworks/Part 1/0f.md b/Node_Week_2/expressworks/Part 1/0f.md index 140b930f..64c5711d 100644 --- a/Node_Week_2/expressworks/Part 1/0f.md +++ b/Node_Week_2/expressworks/Part 1/0f.md @@ -1,10 +1,11 @@ -PUT also sends data to a resource. Unlike POST, if the data already exists there (with the same file name), PUT replaces that file. If there is no file there, PUT will create one. +PUT updates and replaces data in server. It is the **U** in **CRUD**. Unlike POST, if the data already exists there (with the same file name), PUT replaces that file. If there is no file there, PUT will create one. ```javascript -app.put('/user', function (req, res) { // PUT request to the 'user' route - res.send('put it!') +app.put('/user/:id', function (req, res) { + const movie = req.params.id; + res.send('put it!') }) ``` diff --git a/Node_Week_2/expressworks/Part 1/0g.md b/Node_Week_2/expressworks/Part 1/0g.md index bfe52573..e88e3200 100644 --- a/Node_Week_2/expressworks/Part 1/0g.md +++ b/Node_Week_2/expressworks/Part 1/0g.md @@ -1,9 +1,10 @@ -The DELETE method will delete some data or file from the server side. +The DELETE method will delete data from the server. It is the **D** in **CRUD**. If we want to delete some data on the file route, we will use ``/file`` as the handle and delete it like so: ```javascript -app.delete ('/file', function (req, res) { // DELETE request to the 'file' route +app.delete ('/file:id', function (req, res) { + const movie = req.params.id; res.send('deleted it!') }) ``` diff --git a/Node_Week_2/js-best-practices/.DS_Store b/Node_Week_2/js-best-practices/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1aea510c46980d17f21d97c17a668780e7af741c GIT binary patch literal 8196 zcmeHMO^ee&7=CBBuG22d_OQ71mW$|Nk$%Y5Ma0;xhXs*^hzcsZNn6@rnkh|c(ORiL zLAOt`0FYw}@@Zi<;oe#T7n^i%SLT6y+nPi?flRQuJ@lFANRC@ISKn?&X zR*ulFT1wQ{Lps&Mpp#8^#)Sz+;sgq>sMIMuLt5dmK>loP1AeX z++a{TpWiSF<*ng{F({X@f3CDS9H!~|slvsb{q}>0gGa;1FT|w)QO^@tmD}U?WzvOu z&4N{9?T%zEzfa<{S+%Ofpda6{Yq!3CxSY(Z{}Hd#iq2{9sizFPZ*_f-`Ar<-*F&KR zE-u8Jg?nfzn#vbsB8I*}PSnsP*aaK97-2vm&L!)=;?A1!cz* z$q6xwQPZBTeL21TZORbj9Gdp}S)ysh-mOQm7~}HXX0G- zNoWPM0{=z>EhsF{Z+i XMBIbr|1SjauU!597vk$?ZWZ_e)-Qx% literal 0 HcmV?d00001 From fb28855b0a241b70eb16a2b1e9c58829484b7598 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Tue, 18 Feb 2020 16:55:40 -0800 Subject: [PATCH 06/23] updated GET card to fix some mistakes/add more info --- Node_Week_2/expressworks/Part 1/0d.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Node_Week_2/expressworks/Part 1/0d.md b/Node_Week_2/expressworks/Part 1/0d.md index a223bad6..d947d942 100644 --- a/Node_Week_2/expressworks/Part 1/0d.md +++ b/Node_Week_2/expressworks/Part 1/0d.md @@ -31,4 +31,14 @@ app.get('/home', function (req, res) { }) ``` -Here, \ No newline at end of file +Lets say instead you want to get all of your favorite movies of a page called ``fav_movies``: + +```js +app.get('/fav_movie:movies', function (req, res) { + //TODO: add in another use-case +}) + + +``` + +![An example GET request on Github](https://res.cloudinary.com/indysigner/image/fetch/f_auto,q_auto/w_400/https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/b6d1a8b7-51ef-45d2-a416-b34d7c76abda/understanding-api-doc-github-repo-get-opt.png) \ No newline at end of file From 1e08e197efd118e8794448891619c377ee2d8d79 Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Tue, 18 Feb 2020 17:46:10 -0800 Subject: [PATCH 07/23] Begin js-best-practices, 9.md --- .../Act12_Intro to NLP/.11.html.icloud | Bin 0 -> 157 bytes .../activities/Act12_Intro to NLP/11.html | 21404 ---------------- Node_Week_2/expressworks/Part 2/9.md | 1 - Node_Week_2/js-best-practices/Part 1/1.md | 140 +- Node_Week_2/js-best-practices/Part 1/2.md | 2 +- 5 files changed, 96 insertions(+), 21451 deletions(-) create mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/.11.html.icloud delete mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/11.html diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/.11.html.icloud b/Module_Twitter_API/activities/Act12_Intro to NLP/.11.html.icloud new file mode 100644 index 0000000000000000000000000000000000000000..d79aeaba876df9759b1984ce93e3850965f48550 GIT binary patch literal 157 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFa6?1AjFQ|OAqJD&tat$#tm=YN(@S#_i#YgY^u2<@8Nh&%5kfPtLunXQ F1_1i#DP8~o literal 0 HcmV?d00001 diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/11.html b/Module_Twitter_API/activities/Act12_Intro to NLP/11.html deleted file mode 100644 index 676a1a12..00000000 --- a/Module_Twitter_API/activities/Act12_Intro to NLP/11.html +++ /dev/null @@ -1,21404 +0,0 @@ - - -Natural Language Processing (NLP) Tutorial with Python & NLTK - YouTube - - -/* Most common used flex styles*/ - - - -/* Basic flexbox reverse styles */ - - - -/* Flexbox alignment */ - - - -/* Non-flexbox positioning helper styles */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
-
-
- - - Back - - - - - - - - - - -
-
- - -
- - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
- - - -
- - -
- -
-
-
- -
- -
-
-
- -
-
- - - - - - - - - - - -
- -
- -
- -
- -
-
-
-
-
-
- -
-
- -
-
- - -
- -
-
-
- - -
- - -
-
-
-
-
-
-
-
-
-
-
- -
-
-

Natural Language Processing (NLP) Tutorial with Python & NLTK

52,710 views52K views
Sep 27, 2018
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
- -
-
-
-
- -
-
-
- -
-
- -
- - - - - -
- - - -
- - - - - - - - - - -
- -
-
1.61M subscribers
- - - Subscribe - - - -
- -
- -
This video will provide you with a comprehensive and detailed knowledge of Natural Language Processing, popularly known as NLP. You will also learn about the different steps involved in processing the human language like Tokenization, Stemming, Lemmatization and more. Python, NLTK, & Jupyter Notebook are used to demonstrate the concepts. - -This tutorial was developed by Edureka. - -🔗NLP Certification Training: https://goo.gl/kn2H8T - -🔗Subscribe to the Edureka YouTube channel: https://www.youtube.com/user/edurekaIN - -🔗Edureka Online Training: https://www.edureka.co/ - --- - -Learn to code for free and get a developer job: https://www.freecodecamp.org - -Read hundreds of articles on programming: https://medium.freecodecamp.org - -And subscribe for new videos on technology every day: https://youtube.com/subscription_cent...
-
- - - - - - - -
-
-
-
- - - - - - - -
- -
-
-
- - - - - - -
-
-
-
-
- -
-
- - - - - - - -
-
-
- - - -
- - - - -
-
-
- -
-
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
\ No newline at end of file diff --git a/Node_Week_2/expressworks/Part 2/9.md b/Node_Week_2/expressworks/Part 2/9.md index d2f7772d..e62b3f28 100644 --- a/Node_Week_2/expressworks/Part 2/9.md +++ b/Node_Week_2/expressworks/Part 2/9.md @@ -73,4 +73,3 @@ app.get('/json', function(req, res) { } }) ``` - diff --git a/Node_Week_2/js-best-practices/Part 1/1.md b/Node_Week_2/js-best-practices/Part 1/1.md index 9e756a7a..beb5ca64 100644 --- a/Node_Week_2/js-best-practices/Part 1/1.md +++ b/Node_Week_2/js-best-practices/Part 1/1.md @@ -17,52 +17,102 @@ as some bad practices to avoid. Here's an overview of the concepts we're going t Below is the code for a file you should name `vendingMachine.js`. Although the code works, you'll fix the code so that the code is much more maintanable and understandable. ```js -var fs = require('fs'); -var path = require('path'); -var shop = require('../../js-best-practices'); - -module.exports = function buildExercise(){ - printProblem().then(function(){ - return waitForInput('press any key to continue...'); - }).then(function(){ - shop.execute(['init']); - }); +var balanceManager = require('./balanceManager'); +var changeHandler = require('./changeHandler'); +var productInventory = require('./productInventory'); + +var balance = 0; + +var products = [ + { + name: 'Skittles', + price: 85, + id: 'A1' + } +]; + +module.exports = { + canAfford: function(amount){ + if(!this.isValidAmount(amount)){ + errorMessage = "Invalid Input"; + } + if(errorMessage){ + throw new Error(errorMessage); + } + return amount <= balance; + }, + + decreaseBalance: function(amount){ + // This method decreases the balance of the vending machine. If the balance amount is not + // enough to cover the purchase, the method throws an error. + var errorMessage; + if(!this.canAfford(amount)){ + errorMessage = 'Insufficient balance'; + } + if(errorMessage){ + throw new Error(errorMessage); + } + balance -= amount; + }, + + getAmount: function(coinType) { + // COINS: + // [p]enny + // [n]ickel + // [d]ime + // [q]uarter + switch(coinType){ + case 'p': return 1; + case 'n': return 5; + case 'd': return 10; + case 'q': return 25; + default: throw new Error('Unrecognized coin ' + coinType); + } + }, + + getBalance: function(){ + return balance; + }, + + getProducts: function() { + return products; + }, + + getProduct: function(productId) { + var product = products.find(function(p) { return p.id === productId; }); + return product; + }, - return { - noprint: true - }; -} - -function waitForInput(prompt){ - return new Promise(function(res, rej){ - console.log(prompt); - var alreadyRaw = process.stdin.isRaw; - process.stdin.setRawMode(true); - process.stdin.resume(); - process.stdin.once('data', function(){ - process.stdin.pause(); - process.stdin.setRawMode(alreadyRaw); - res(); - }); - }); -} - -function printProblem(){ - return new Promise(function(res, rej){ - var lang = shop.i18n.lang() - var problem = fs.readFileSync(path.join(__dirname, 'problem' + (lang === 'en' ? '' : '.' + lang) + '.md')); - var stream = shop.createMarkdownStream({ - meta: { - name: 'get started', - number: 0 - } - }); - stream.append(problem, 'md'); - stream.pipe(require('workshopper-adventure/lib/mseePipe')()) - .pipe(process.stdout) - stream.on('end', res); - }); -} + increaseBalance: function(amount){ + balance += amount; + }, + + insertCoin: function(coinType){ + var value = this.getAmount(coinType); + this.increaseBalance(value); + }, + + isValidAmount: function(amount){ + if(amount === null){ + return false; + } else { + return true; + } + }, + + releaseChange: function(){ + var currentBalance = this.getBalance(); + this.decreaseBalance(currentBalance); + return this.convertToChange(currentBalance); + }, + + vendProduct: function(productId){ + var product = this.getProduct(productId); + this.decreaseBalance(product.price); + return product; + } + +}; ``` diff --git a/Node_Week_2/js-best-practices/Part 1/2.md b/Node_Week_2/js-best-practices/Part 1/2.md index 614a4b4e..2b918c32 100644 --- a/Node_Week_2/js-best-practices/Part 1/2.md +++ b/Node_Week_2/js-best-practices/Part 1/2.md @@ -1,6 +1,6 @@ - +Now that we've # Separation of Concerns Part 1 From 07fb08de3d9ce278881807f5c0f6e5aa1fcf52d5 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Wed, 19 Feb 2020 10:50:42 -0800 Subject: [PATCH 08/23] minor grammar and visual fixes --- .../.DS_Store | Bin 0 -> 6148 bytes .../Act3_Creating_Postman_Collections/1.md | 70 +++++++------- .../Act3_Creating_Postman_Collections/2.md | 57 ++++++----- .../Act3_Creating_Postman_Collections/3.md | 37 ++++--- .../Act3_Creating_Postman_Collections/4.md | 48 +++++----- .../Act3_Creating_Postman_Collections/5.md | 28 +++--- .../Act3_Creating_Postman_Collections/6.md | 16 ++-- .../Act3_Creating_Postman_Collections/7.md | 20 ++-- .../Act3_Creating_Postman_Collections/8.md | 90 +++++++++--------- .../Act3_Creating_Postman_Collections/9.md | 80 ++++++++-------- 10 files changed, 225 insertions(+), 221 deletions(-) create mode 100644 Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store b/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f7823389c0d37450a476c4f9424eb6644b6c14ba GIT binary patch literal 6148 zcmeHKyG{c!5Znz$I-p4h<&{)OAv{H6MWLYP2T(|vC>0VFy3gPj_)3_4D8hG62|{RB zT93URd(U&y`Id-y_OhH1jftp%3yu!ZR7~c@2R8D^A&_N{ht=kJvDz#!mJP%Hz5?>@ z5>4og*0k)szdOvGeyZs~_Q8AG#pKs-%tYr^-bZi8MAI6Nj|aSq8js`&-;2DLRi5N6 zc~>=_<}G>GHJ;?)*Kl|8w!L1p}>Zb#ZmH@znup0XM>kn)t0L+e^AtErgr9fNCUShCU4s6RYpPk7It%JkK tUE9K+;9|n-47W?r(W@9-xr$HVYKXVe0cOX}5D{4X2&fFvgaW^+z!zaod@BF| literal 0 HcmV?d00001 diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md index d8d834ab..3791c121 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md @@ -1,35 +1,35 @@ - - -# Creating Collections - -**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: - -* **D**on't -* **R**epeat -* **Y**ourself - - - -To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: - -​ - -A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. - -#### Color Changer Collection: - -We are going to create a collection for our requests for the BitBloxs API. - -**Steps:** - -* Click **+ New Collection** -* Name the collection **Color Changer** -* Provide any description you think necessary -* Click **Create** - -On your collection sidebar, you should see the new collection we just created: - - - -We will be using this collection to learn how to add requests to collections and create documentation for collections. - + + +# Creating Collections + +**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: + +* **D**on't +* **R**epeat +* **Y**ourself + + + +To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: + +​ + +A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. + +#### Color Changer Collection: + +We are going to create a collection for our requests for the BitBloxs API. + +**Steps:** + +* Click **+ New Collection** +* Name the collection **Color Changer** +* Provide any description you think necessary +* Click **Create** + +On your collection sidebar, you should see the new collection we just created: + +![VySgvL0](https://i.imgur.com/VySgvL0.png) + +We will be using this collection to learn how to add requests to collections and create documentation for collections. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md index e54fb0b1..83a730ed 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md @@ -1,25 +1,32 @@ - - -# Creating Environments - -Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time because instead having to retype long elements, such as a URL, we can simply use the variable name instead. - -To create an environment, you click the large **NEW** button and then **Environment**. - -#### Color Changer Environment: - -Let's walk through making a new environment for our BitBloxs API. Create a new environment that we'll name **Deploy**. You'll see this table to create the variables: - - - -In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: - - - -Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: - - - -Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**. - -To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. \ No newline at end of file + + +# Creating Environments + +Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time: instead of having to retype long elements, such as an URL, we can simply use the variable name instead. + +To create an environment, click the large **NEW** button on the top left corner and then click on **Environment**. + +![K9ISonC](https://i.imgur.com/K9ISonC.png) + +![61W4VvY](https://i.imgur.com/61W4VvY.png) + +Color Changer Environment: + +Now we are going to walk you through creating the new environment for our BitBloxs API. Lets name our new environment **Deploy** where it says ``Environment name``. The table under that will alow us to create the variables: + +![3qyR5SU](https://i.imgur.com/3qyR5SU.png) + +In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: + +![mZFKhuY](https://i.imgur.com/mZFKhuY.png) + +Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: + +SdM5WA2 + +Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**: + +qU9q2pw + +To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md index ed235601..49507c0b 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md @@ -1,20 +1,17 @@ - - -# Adding Requests to Collections - -Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, click on the `...` icon next to the collection: - - - - - -Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making. - -#### Color Changer Collection: - -We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. - - - - - + + +# Adding Requests to Collections + +Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, hover your mouse over the collection and then click on the `...` icon next to the collection: + +W8URfi5 + +Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making: + +hr6SCEl + +#### Color Changer Collection: + +We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. + + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md index b0b8a0d7..489d18dd 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md @@ -1,24 +1,24 @@ - - -# First Request (GET): - -The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: - -* Create a new request in the Color Changer collection -* Name the request `Get all boxes` -* Add API key authentication to this request - -To add authentication to our requests, first click the **Authentication** tab in the request window: - - - -Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: - - - -Now that we've established our credentials, let's create the route. To do so, refer to the route bar: - - - -Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. - + + +# First Request (GET): + +The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: + +* Create a new request in the Color Changer collection +* Name the request `Get all boxes` +* Add API key authentication to this request + +To add the API key authentication to our requests, first click the **Authorization** tab in the request window: + + + +Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: + + + +Now that we've established our credentials, let's create the route. To do so, refer to the route bar: + + + +Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md index 741b176f..22c3b5ac 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md @@ -1,14 +1,14 @@ - - -# Second Request (POST): - -The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. - -To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. - -To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: - - - -If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. - + + +# Second Request (POST): + +The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. + +To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. + +To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: + + + +If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md index ba9e79d6..cdcc9536 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md @@ -1,9 +1,9 @@ - - -# Third Request (PUT): - -To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: - - - + + +# Third Request (PUT): + +To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: + + + If you send the request, it should successfully change the color of box 202 to yellow. The case where this PUT request will result in an error is if the box has not been initialized to a color yet. To initialize the color we must use the POST request from our collection. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md index a224a40d..48821c48 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md @@ -1,11 +1,11 @@ - - -# Fourth Request (DELETE): - -The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: - - - - - + + +# Fourth Request (DELETE): + +The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: + + + + + The requests we added to Color Changer are just some of the basic essentials needed to use Postman with your APIs. Postman has many features that allow you to test the functionality of APIs that you can continue to explore. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md index b50b4139..88670144 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md @@ -1,46 +1,46 @@ - - -# Generating Documentation - -Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. - -One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. - -#### Color Changer Collection: - -We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: - - - -Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. - -However, we want to add more details to our documentation. The easy way to do so would be to: - -* Click the **New** button -* Click **API Documentation** -* Click the **Select an existing collection** -* Click **Color Changer** - -Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. - -After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. - -The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. - -To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: - - - -Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. - - - -Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. - - - - - - - + + +# Generating Documentation + +Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. + +One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. + +#### Color Changer Collection: + +We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: + + + +Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. + +However, we want to add more details to our documentation. The easy way to do so would be to: + +* Click the **New** button +* Click **API Documentation** +* Click the **Select an existing collection** +* Click **Color Changer** + +Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. + +After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. + +The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. + +To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: + + + +Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. + + + +Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. + + + + + + + \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md index db5165df..2cabe4d5 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md @@ -1,40 +1,40 @@ - - -# Importing API Collections - -Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. - -On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. - - - -Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: - - - -Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: - - - -If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: - - - -Now that you have your access token copied to your clipboard, let's authorize our request in Postman: - - - -Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. - -Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: - - - -Now if we click **Send**, our request should go through and the response should look something like: - - - - - -There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. - + + +# Importing API Collections + +Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. + +On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. + + + +Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: + + + +Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: + + + +If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: + + + +Now that you have your access token copied to your clipboard, let's authorize our request in Postman: + + + +Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. + +Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: + + + +Now if we click **Send**, our request should go through and the response should look something like: + + + + + +There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. + From d7529871ab738e4c85d63c71bbcda78648e51656 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Wed, 19 Feb 2020 10:50:59 -0800 Subject: [PATCH 09/23] Revert "minor grammar and visual fixes" This reverts commit 07fb08de3d9ce278881807f5c0f6e5aa1fcf52d5. --- .../.DS_Store | Bin 6148 -> 0 bytes .../Act3_Creating_Postman_Collections/1.md | 70 +++++++------- .../Act3_Creating_Postman_Collections/2.md | 57 +++++------ .../Act3_Creating_Postman_Collections/3.md | 37 +++---- .../Act3_Creating_Postman_Collections/4.md | 48 +++++----- .../Act3_Creating_Postman_Collections/5.md | 28 +++--- .../Act3_Creating_Postman_Collections/6.md | 16 ++-- .../Act3_Creating_Postman_Collections/7.md | 20 ++-- .../Act3_Creating_Postman_Collections/8.md | 90 +++++++++--------- .../Act3_Creating_Postman_Collections/9.md | 80 ++++++++-------- 10 files changed, 221 insertions(+), 225 deletions(-) delete mode 100644 Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store b/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store deleted file mode 100644 index f7823389c0d37450a476c4f9424eb6644b6c14ba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c!5Znz$I-p4h<&{)OAv{H6MWLYP2T(|vC>0VFy3gPj_)3_4D8hG62|{RB zT93URd(U&y`Id-y_OhH1jftp%3yu!ZR7~c@2R8D^A&_N{ht=kJvDz#!mJP%Hz5?>@ z5>4og*0k)szdOvGeyZs~_Q8AG#pKs-%tYr^-bZi8MAI6Nj|aSq8js`&-;2DLRi5N6 zc~>=_<}G>GHJ;?)*Kl|8w!L1p}>Zb#ZmH@znup0XM>kn)t0L+e^AtErgr9fNCUShCU4s6RYpPk7It%JkK tUE9K+;9|n-47W?r(W@9-xr$HVYKXVe0cOX}5D{4X2&fFvgaW^+z!zaod@BF| diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md index 3791c121..d8d834ab 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md @@ -1,35 +1,35 @@ - - -# Creating Collections - -**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: - -* **D**on't -* **R**epeat -* **Y**ourself - - - -To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: - -​ - -A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. - -#### Color Changer Collection: - -We are going to create a collection for our requests for the BitBloxs API. - -**Steps:** - -* Click **+ New Collection** -* Name the collection **Color Changer** -* Provide any description you think necessary -* Click **Create** - -On your collection sidebar, you should see the new collection we just created: - -![VySgvL0](https://i.imgur.com/VySgvL0.png) - -We will be using this collection to learn how to add requests to collections and create documentation for collections. - + + +# Creating Collections + +**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: + +* **D**on't +* **R**epeat +* **Y**ourself + + + +To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: + +​ + +A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. + +#### Color Changer Collection: + +We are going to create a collection for our requests for the BitBloxs API. + +**Steps:** + +* Click **+ New Collection** +* Name the collection **Color Changer** +* Provide any description you think necessary +* Click **Create** + +On your collection sidebar, you should see the new collection we just created: + + + +We will be using this collection to learn how to add requests to collections and create documentation for collections. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md index 83a730ed..e54fb0b1 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md @@ -1,32 +1,25 @@ - - -# Creating Environments - -Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time: instead of having to retype long elements, such as an URL, we can simply use the variable name instead. - -To create an environment, click the large **NEW** button on the top left corner and then click on **Environment**. - -![K9ISonC](https://i.imgur.com/K9ISonC.png) - -![61W4VvY](https://i.imgur.com/61W4VvY.png) - -Color Changer Environment: - -Now we are going to walk you through creating the new environment for our BitBloxs API. Lets name our new environment **Deploy** where it says ``Environment name``. The table under that will alow us to create the variables: - -![3qyR5SU](https://i.imgur.com/3qyR5SU.png) - -In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: - -![mZFKhuY](https://i.imgur.com/mZFKhuY.png) - -Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: - -SdM5WA2 - -Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**: - -qU9q2pw - -To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. - + + +# Creating Environments + +Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time because instead having to retype long elements, such as a URL, we can simply use the variable name instead. + +To create an environment, you click the large **NEW** button and then **Environment**. + +#### Color Changer Environment: + +Let's walk through making a new environment for our BitBloxs API. Create a new environment that we'll name **Deploy**. You'll see this table to create the variables: + + + +In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: + + + +Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: + + + +Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**. + +To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md index 49507c0b..ed235601 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md @@ -1,17 +1,20 @@ - - -# Adding Requests to Collections - -Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, hover your mouse over the collection and then click on the `...` icon next to the collection: - -W8URfi5 - -Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making: - -hr6SCEl - -#### Color Changer Collection: - -We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. - - + + +# Adding Requests to Collections + +Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, click on the `...` icon next to the collection: + + + + + +Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making. + +#### Color Changer Collection: + +We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. + + + + + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md index 489d18dd..b0b8a0d7 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md @@ -1,24 +1,24 @@ - - -# First Request (GET): - -The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: - -* Create a new request in the Color Changer collection -* Name the request `Get all boxes` -* Add API key authentication to this request - -To add the API key authentication to our requests, first click the **Authorization** tab in the request window: - - - -Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: - - - -Now that we've established our credentials, let's create the route. To do so, refer to the route bar: - - - -Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. - + + +# First Request (GET): + +The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: + +* Create a new request in the Color Changer collection +* Name the request `Get all boxes` +* Add API key authentication to this request + +To add authentication to our requests, first click the **Authentication** tab in the request window: + + + +Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: + + + +Now that we've established our credentials, let's create the route. To do so, refer to the route bar: + + + +Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md index 22c3b5ac..741b176f 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md @@ -1,14 +1,14 @@ - - -# Second Request (POST): - -The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. - -To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. - -To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: - - - -If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. - + + +# Second Request (POST): + +The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. + +To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. + +To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: + + + +If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md index cdcc9536..ba9e79d6 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md @@ -1,9 +1,9 @@ - - -# Third Request (PUT): - -To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: - - - + + +# Third Request (PUT): + +To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: + + + If you send the request, it should successfully change the color of box 202 to yellow. The case where this PUT request will result in an error is if the box has not been initialized to a color yet. To initialize the color we must use the POST request from our collection. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md index 48821c48..a224a40d 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md @@ -1,11 +1,11 @@ - - -# Fourth Request (DELETE): - -The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: - - - - - + + +# Fourth Request (DELETE): + +The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: + + + + + The requests we added to Color Changer are just some of the basic essentials needed to use Postman with your APIs. Postman has many features that allow you to test the functionality of APIs that you can continue to explore. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md index 88670144..b50b4139 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md @@ -1,46 +1,46 @@ - - -# Generating Documentation - -Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. - -One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. - -#### Color Changer Collection: - -We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: - - - -Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. - -However, we want to add more details to our documentation. The easy way to do so would be to: - -* Click the **New** button -* Click **API Documentation** -* Click the **Select an existing collection** -* Click **Color Changer** - -Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. - -After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. - -The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. - -To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: - - - -Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. - - - -Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. - - - - - - - + + +# Generating Documentation + +Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. + +One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. + +#### Color Changer Collection: + +We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: + + + +Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. + +However, we want to add more details to our documentation. The easy way to do so would be to: + +* Click the **New** button +* Click **API Documentation** +* Click the **Select an existing collection** +* Click **Color Changer** + +Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. + +After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. + +The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. + +To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: + + + +Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. + + + +Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. + + + + + + + \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md index 2cabe4d5..db5165df 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md @@ -1,40 +1,40 @@ - - -# Importing API Collections - -Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. - -On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. - - - -Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: - - - -Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: - - - -If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: - - - -Now that you have your access token copied to your clipboard, let's authorize our request in Postman: - - - -Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. - -Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: - - - -Now if we click **Send**, our request should go through and the response should look something like: - - - - - -There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. - + + +# Importing API Collections + +Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. + +On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. + + + +Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: + + + +Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: + + + +If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: + + + +Now that you have your access token copied to your clipboard, let's authorize our request in Postman: + + + +Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. + +Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: + + + +Now if we click **Send**, our request should go through and the response should look something like: + + + + + +There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. + From 44c8fafe17a5d3b9c078a9680faf08b85891efa1 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Wed, 19 Feb 2020 10:51:37 -0800 Subject: [PATCH 10/23] Revert "Revert "minor grammar and visual fixes"" This reverts commit d7529871ab738e4c85d63c71bbcda78648e51656. --- .../.DS_Store | Bin 0 -> 6148 bytes .../Act3_Creating_Postman_Collections/1.md | 70 +++++++------- .../Act3_Creating_Postman_Collections/2.md | 57 ++++++----- .../Act3_Creating_Postman_Collections/3.md | 37 ++++--- .../Act3_Creating_Postman_Collections/4.md | 48 +++++----- .../Act3_Creating_Postman_Collections/5.md | 28 +++--- .../Act3_Creating_Postman_Collections/6.md | 16 ++-- .../Act3_Creating_Postman_Collections/7.md | 20 ++-- .../Act3_Creating_Postman_Collections/8.md | 90 +++++++++--------- .../Act3_Creating_Postman_Collections/9.md | 80 ++++++++-------- 10 files changed, 225 insertions(+), 221 deletions(-) create mode 100644 Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store b/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f7823389c0d37450a476c4f9424eb6644b6c14ba GIT binary patch literal 6148 zcmeHKyG{c!5Znz$I-p4h<&{)OAv{H6MWLYP2T(|vC>0VFy3gPj_)3_4D8hG62|{RB zT93URd(U&y`Id-y_OhH1jftp%3yu!ZR7~c@2R8D^A&_N{ht=kJvDz#!mJP%Hz5?>@ z5>4og*0k)szdOvGeyZs~_Q8AG#pKs-%tYr^-bZi8MAI6Nj|aSq8js`&-;2DLRi5N6 zc~>=_<}G>GHJ;?)*Kl|8w!L1p}>Zb#ZmH@znup0XM>kn)t0L+e^AtErgr9fNCUShCU4s6RYpPk7It%JkK tUE9K+;9|n-47W?r(W@9-xr$HVYKXVe0cOX}5D{4X2&fFvgaW^+z!zaod@BF| literal 0 HcmV?d00001 diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md index d8d834ab..3791c121 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md @@ -1,35 +1,35 @@ - - -# Creating Collections - -**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: - -* **D**on't -* **R**epeat -* **Y**ourself - - - -To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: - -​ - -A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. - -#### Color Changer Collection: - -We are going to create a collection for our requests for the BitBloxs API. - -**Steps:** - -* Click **+ New Collection** -* Name the collection **Color Changer** -* Provide any description you think necessary -* Click **Create** - -On your collection sidebar, you should see the new collection we just created: - - - -We will be using this collection to learn how to add requests to collections and create documentation for collections. - + + +# Creating Collections + +**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: + +* **D**on't +* **R**epeat +* **Y**ourself + + + +To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: + +​ + +A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. + +#### Color Changer Collection: + +We are going to create a collection for our requests for the BitBloxs API. + +**Steps:** + +* Click **+ New Collection** +* Name the collection **Color Changer** +* Provide any description you think necessary +* Click **Create** + +On your collection sidebar, you should see the new collection we just created: + +![VySgvL0](https://i.imgur.com/VySgvL0.png) + +We will be using this collection to learn how to add requests to collections and create documentation for collections. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md index e54fb0b1..83a730ed 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md @@ -1,25 +1,32 @@ - - -# Creating Environments - -Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time because instead having to retype long elements, such as a URL, we can simply use the variable name instead. - -To create an environment, you click the large **NEW** button and then **Environment**. - -#### Color Changer Environment: - -Let's walk through making a new environment for our BitBloxs API. Create a new environment that we'll name **Deploy**. You'll see this table to create the variables: - - - -In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: - - - -Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: - - - -Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**. - -To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. \ No newline at end of file + + +# Creating Environments + +Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time: instead of having to retype long elements, such as an URL, we can simply use the variable name instead. + +To create an environment, click the large **NEW** button on the top left corner and then click on **Environment**. + +![K9ISonC](https://i.imgur.com/K9ISonC.png) + +![61W4VvY](https://i.imgur.com/61W4VvY.png) + +Color Changer Environment: + +Now we are going to walk you through creating the new environment for our BitBloxs API. Lets name our new environment **Deploy** where it says ``Environment name``. The table under that will alow us to create the variables: + +![3qyR5SU](https://i.imgur.com/3qyR5SU.png) + +In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: + +![mZFKhuY](https://i.imgur.com/mZFKhuY.png) + +Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: + +SdM5WA2 + +Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**: + +qU9q2pw + +To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md index ed235601..49507c0b 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md @@ -1,20 +1,17 @@ - - -# Adding Requests to Collections - -Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, click on the `...` icon next to the collection: - - - - - -Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making. - -#### Color Changer Collection: - -We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. - - - - - + + +# Adding Requests to Collections + +Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, hover your mouse over the collection and then click on the `...` icon next to the collection: + +W8URfi5 + +Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making: + +hr6SCEl + +#### Color Changer Collection: + +We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. + + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md index b0b8a0d7..489d18dd 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md @@ -1,24 +1,24 @@ - - -# First Request (GET): - -The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: - -* Create a new request in the Color Changer collection -* Name the request `Get all boxes` -* Add API key authentication to this request - -To add authentication to our requests, first click the **Authentication** tab in the request window: - - - -Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: - - - -Now that we've established our credentials, let's create the route. To do so, refer to the route bar: - - - -Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. - + + +# First Request (GET): + +The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: + +* Create a new request in the Color Changer collection +* Name the request `Get all boxes` +* Add API key authentication to this request + +To add the API key authentication to our requests, first click the **Authorization** tab in the request window: + + + +Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: + + + +Now that we've established our credentials, let's create the route. To do so, refer to the route bar: + + + +Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md index 741b176f..22c3b5ac 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md @@ -1,14 +1,14 @@ - - -# Second Request (POST): - -The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. - -To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. - -To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: - - - -If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. - + + +# Second Request (POST): + +The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. + +To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. + +To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: + + + +If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md index ba9e79d6..cdcc9536 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md @@ -1,9 +1,9 @@ - - -# Third Request (PUT): - -To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: - - - + + +# Third Request (PUT): + +To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: + + + If you send the request, it should successfully change the color of box 202 to yellow. The case where this PUT request will result in an error is if the box has not been initialized to a color yet. To initialize the color we must use the POST request from our collection. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md index a224a40d..48821c48 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md @@ -1,11 +1,11 @@ - - -# Fourth Request (DELETE): - -The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: - - - - - + + +# Fourth Request (DELETE): + +The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: + + + + + The requests we added to Color Changer are just some of the basic essentials needed to use Postman with your APIs. Postman has many features that allow you to test the functionality of APIs that you can continue to explore. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md index b50b4139..88670144 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md @@ -1,46 +1,46 @@ - - -# Generating Documentation - -Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. - -One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. - -#### Color Changer Collection: - -We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: - - - -Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. - -However, we want to add more details to our documentation. The easy way to do so would be to: - -* Click the **New** button -* Click **API Documentation** -* Click the **Select an existing collection** -* Click **Color Changer** - -Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. - -After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. - -The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. - -To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: - - - -Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. - - - -Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. - - - - - - - + + +# Generating Documentation + +Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. + +One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. + +#### Color Changer Collection: + +We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: + + + +Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. + +However, we want to add more details to our documentation. The easy way to do so would be to: + +* Click the **New** button +* Click **API Documentation** +* Click the **Select an existing collection** +* Click **Color Changer** + +Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. + +After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. + +The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. + +To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: + + + +Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. + + + +Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. + + + + + + + \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md index db5165df..2cabe4d5 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md @@ -1,40 +1,40 @@ - - -# Importing API Collections - -Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. - -On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. - - - -Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: - - - -Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: - - - -If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: - - - -Now that you have your access token copied to your clipboard, let's authorize our request in Postman: - - - -Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. - -Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: - - - -Now if we click **Send**, our request should go through and the response should look something like: - - - - - -There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. - + + +# Importing API Collections + +Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. + +On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. + + + +Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: + + + +Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: + + + +If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: + + + +Now that you have your access token copied to your clipboard, let's authorize our request in Postman: + + + +Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. + +Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: + + + +Now if we click **Send**, our request should go through and the response should look something like: + + + + + +There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. + From 09147b4078dca35ac0c93c7c9226b74d6ebfd1c3 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Thu, 20 Feb 2020 13:32:25 -0800 Subject: [PATCH 11/23] Create README.md --- .../README.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Module_Postman/activities/Act3_Creating_Postman_Collections/README.md diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/README.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/README.md new file mode 100644 index 00000000..697f0c9d --- /dev/null +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/README.md @@ -0,0 +1,27 @@ +# Activity Name + +Creating Collections in Postman + +# Long Summary + +Students will be able to create collections in postman. The content of the collections are the 4 Restful API methods: GET, DELETE, PUT, POST. + +This activity also contains how to create documentation and importing collections + +# Short Summary + +Create collections in postman through adding Restful API methods + +# Criteria + +1. On a very high level, describe how collections are used. +2. What would happen if you tried to use a collection without evironment variables set up? +3. What kinds of collections can you import? What can these kinds of collections accomplish? + +# Difficulty + +Easy + +# Image + +![VySgvL0](https://i.imgur.com/VySgvL0.png) \ No newline at end of file From 4fd728377cb30e09554ea3e604f4276cd13f133c Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Thu, 20 Feb 2020 17:20:03 -0800 Subject: [PATCH 12/23] Revert "Create README.md" This reverts commit 09147b4078dca35ac0c93c7c9226b74d6ebfd1c3. --- .../README.md | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 Module_Postman/activities/Act3_Creating_Postman_Collections/README.md diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/README.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/README.md deleted file mode 100644 index 697f0c9d..00000000 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Activity Name - -Creating Collections in Postman - -# Long Summary - -Students will be able to create collections in postman. The content of the collections are the 4 Restful API methods: GET, DELETE, PUT, POST. - -This activity also contains how to create documentation and importing collections - -# Short Summary - -Create collections in postman through adding Restful API methods - -# Criteria - -1. On a very high level, describe how collections are used. -2. What would happen if you tried to use a collection without evironment variables set up? -3. What kinds of collections can you import? What can these kinds of collections accomplish? - -# Difficulty - -Easy - -# Image - -![VySgvL0](https://i.imgur.com/VySgvL0.png) \ No newline at end of file From 1acf6fddf15d4965575461d18a2b90a10266ccf1 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Thu, 20 Feb 2020 17:20:07 -0800 Subject: [PATCH 13/23] Revert "Revert "Revert "minor grammar and visual fixes""" This reverts commit 44c8fafe17a5d3b9c078a9680faf08b85891efa1. --- .../.DS_Store | Bin 6148 -> 0 bytes .../Act3_Creating_Postman_Collections/1.md | 70 +++++++------- .../Act3_Creating_Postman_Collections/2.md | 57 +++++------ .../Act3_Creating_Postman_Collections/3.md | 37 +++---- .../Act3_Creating_Postman_Collections/4.md | 48 +++++----- .../Act3_Creating_Postman_Collections/5.md | 28 +++--- .../Act3_Creating_Postman_Collections/6.md | 16 ++-- .../Act3_Creating_Postman_Collections/7.md | 20 ++-- .../Act3_Creating_Postman_Collections/8.md | 90 +++++++++--------- .../Act3_Creating_Postman_Collections/9.md | 80 ++++++++-------- 10 files changed, 221 insertions(+), 225 deletions(-) delete mode 100644 Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store b/Module_Postman/activities/Act3_Creating_Postman_Collections/.DS_Store deleted file mode 100644 index f7823389c0d37450a476c4f9424eb6644b6c14ba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyG{c!5Znz$I-p4h<&{)OAv{H6MWLYP2T(|vC>0VFy3gPj_)3_4D8hG62|{RB zT93URd(U&y`Id-y_OhH1jftp%3yu!ZR7~c@2R8D^A&_N{ht=kJvDz#!mJP%Hz5?>@ z5>4og*0k)szdOvGeyZs~_Q8AG#pKs-%tYr^-bZi8MAI6Nj|aSq8js`&-;2DLRi5N6 zc~>=_<}G>GHJ;?)*Kl|8w!L1p}>Zb#ZmH@znup0XM>kn)t0L+e^AtErgr9fNCUShCU4s6RYpPk7It%JkK tUE9K+;9|n-47W?r(W@9-xr$HVYKXVe0cOX}5D{4X2&fFvgaW^+z!zaod@BF| diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md index 3791c121..d8d834ab 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/1.md @@ -1,35 +1,35 @@ - - -# Creating Collections - -**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: - -* **D**on't -* **R**epeat -* **Y**ourself - - - -To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: - -​ - -A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. - -#### Color Changer Collection: - -We are going to create a collection for our requests for the BitBloxs API. - -**Steps:** - -* Click **+ New Collection** -* Name the collection **Color Changer** -* Provide any description you think necessary -* Click **Create** - -On your collection sidebar, you should see the new collection we just created: - -![VySgvL0](https://i.imgur.com/VySgvL0.png) - -We will be using this collection to learn how to add requests to collections and create documentation for collections. - + + +# Creating Collections + +**Collections** in Postman allow us to organize our HTTP requests which makes it easier to automate our API testing. They also allow the user to quickly edit their requests. Organized collections adhere to the **DRY Principle**: + +* **D**on't +* **R**epeat +* **Y**ourself + + + +To create a collection in Postman, click the **+ New Collection** button toward the top of the Postman window: + +​ + +A new window will pop up that will allow you to name your collection and provide a description. Let's walk through an example of making a collection by creating the Color Changer collection. + +#### Color Changer Collection: + +We are going to create a collection for our requests for the BitBloxs API. + +**Steps:** + +* Click **+ New Collection** +* Name the collection **Color Changer** +* Provide any description you think necessary +* Click **Create** + +On your collection sidebar, you should see the new collection we just created: + + + +We will be using this collection to learn how to add requests to collections and create documentation for collections. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md index 83a730ed..e54fb0b1 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/2.md @@ -1,32 +1,25 @@ - - -# Creating Environments - -Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time: instead of having to retype long elements, such as an URL, we can simply use the variable name instead. - -To create an environment, click the large **NEW** button on the top left corner and then click on **Environment**. - -![K9ISonC](https://i.imgur.com/K9ISonC.png) - -![61W4VvY](https://i.imgur.com/61W4VvY.png) - -Color Changer Environment: - -Now we are going to walk you through creating the new environment for our BitBloxs API. Lets name our new environment **Deploy** where it says ``Environment name``. The table under that will alow us to create the variables: - -![3qyR5SU](https://i.imgur.com/3qyR5SU.png) - -In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: - -![mZFKhuY](https://i.imgur.com/mZFKhuY.png) - -Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: - -SdM5WA2 - -Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**: - -qU9q2pw - -To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. - + + +# Creating Environments + +Before we start adding requests to our Color Changer collection, let's create an **environment** that will allow us to store variables. Putting variables in an environment saves us time because instead having to retype long elements, such as a URL, we can simply use the variable name instead. + +To create an environment, you click the large **NEW** button and then **Environment**. + +#### Color Changer Environment: + +Let's walk through making a new environment for our BitBloxs API. Create a new environment that we'll name **Deploy**. You'll see this table to create the variables: + + + +In the **VARIABLE** column, add the variables **url** and **api_key**. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **url**, enter our URL https://bitbloxs.herokuapp.com/. For the **INITAL VALUE** and **CURRENT VALUE** columns corresponding to **api_key**, let's enter a generic API key such as **thisistheapikey**. Here's what your table should look like after you fill it out: + + + +Now you can click **Add**, and our environment will be created. Since we made the new environment, we want to make sure that it is the active environment that Postman will be using when we try to access our variables. To do so, find this part of the Postman window: + + + +Make sure that the bar in the above image indicates that the active environment is **Deploy**. If not, click on the dropdown menu and select **Deploy**. + +To use our environment variables, it requires this format: `{{variableName}}`. We'll get practice using variables when we start adding requests to our collections. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md index 49507c0b..ed235601 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/3.md @@ -1,17 +1,20 @@ - - -# Adding Requests to Collections - -Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, hover your mouse over the collection and then click on the `...` icon next to the collection: - -W8URfi5 - -Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making: - -hr6SCEl - -#### Color Changer Collection: - -We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. - - + + +# Adding Requests to Collections + +Now that we have created our **Color Changer** collection and **Deploy** environment, we can start adding requests to the collection. To add a request to our existing collection, click on the `...` icon next to the collection: + + + + + +Then click **Add Request**. A menu will pop up asking you to name the request and provide an optional description of the request you are making. + +#### Color Changer Collection: + +We will go through examples of adding requests to collections by adding 4 requests to our **Color Changer** collection in the following cards. + + + + + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md index 489d18dd..b0b8a0d7 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/4.md @@ -1,24 +1,24 @@ - - -# First Request (GET): - -The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: - -* Create a new request in the Color Changer collection -* Name the request `Get all boxes` -* Add API key authentication to this request - -To add the API key authentication to our requests, first click the **Authorization** tab in the request window: - - - -Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: - - - -Now that we've established our credentials, let's create the route. To do so, refer to the route bar: - - - -Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. - + + +# First Request (GET): + +The first request that we'll be adding to our **Color Changer** collection is a GET request. Here are the steps we must follow to create the GET request and add it to our collection: + +* Create a new request in the Color Changer collection +* Name the request `Get all boxes` +* Add API key authentication to this request + +To add authentication to our requests, first click the **Authentication** tab in the request window: + + + +Then under **TYPE**, select the option **API Key**. To the right, in the **Key** field, enter api_key. In the **Value** field, enter our variable for our API Key, which is {{api_key}}. For the **Add to** field, ensure that Query Params is selected. Your Authorization window should now look like this: + + + +Now that we've established our credentials, let's create the route. To do so, refer to the route bar: + + + +Make sure that the box on the left reads **GET** because we are making a GET request. In the box that reads `Enter request URL`, let's put our GET request URL, which would be `{{url}}boxes?=&=`. Notice how we are accessing our url variable we established earlier by calling {{url}}. Now if we click **Send**, we should receive a response that lists all the boxes in JSON format, which allows us to see the current status of the BitBloxs. Our GET request is now complete! Make sure to save it by clicking on the **Save** button to the right of **Send**. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md index 22c3b5ac..741b176f 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/5.md @@ -1,14 +1,14 @@ - - -# Second Request (POST): - -The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. - -To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. - -To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: - - - -If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. - + + +# Second Request (POST): + +The next request we want to create is a POST request. A POST request will allow us to initialize the color of a white box. To create our POST request, follow the same first 3 steps from the GET request but name this request `Change color` instead. + +To change make this request into a POST request, in the route bar, change the drop down menu that defaults to GET to the value **POST**. + +To complete our request, we just need to work on the request URL. For the POST request, the generic format of the URL would be `{{url}}change/boxNumber/color`. For `boxNumber`, you can insert the number of the box you want to initialize to a certain color. For `color`, you can insert the color (blue, orange, green, yellow) that you want the box to be initialized to. For example if you want to initialize box 23 to the color green, your request should look like: + + + +If you **Send** that request, you should get a response message saying that you successfully changed the color. However, if you send that same request one more time, you should get an error message. The reason for the error is because you changed the color of the box to green with your first request and therefore can no longer initialize the color of the box, thus resulting in the error. To edit the color of an already initialized box, you need to use our next request. + diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md index cdcc9536..ba9e79d6 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/6.md @@ -1,9 +1,9 @@ - - -# Third Request (PUT): - -To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: - - - + + +# Third Request (PUT): + +To edit the color of a box, we will use a PUT request. The steps to creating a PUT request are the same as the previous requests but instead we will indicate in the route bar that it is a PUT request. For the PUT request, you can name it `Edit color`. Our generic request URL will be `{{url}}change/boxNumer/color`. For example, if you want to change the color of box 202 to yellow, this will be your PUT request: + + + If you send the request, it should successfully change the color of box 202 to yellow. The case where this PUT request will result in an error is if the box has not been initialized to a color yet. To initialize the color we must use the POST request from our collection. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md index 48821c48..a224a40d 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/7.md @@ -1,11 +1,11 @@ - - -# Fourth Request (DELETE): - -The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: - - - - - + + +# Fourth Request (DELETE): + +The last request that we will add to our Color Changer collection is a DELETE request. Our DELETE request will remove the color from the specified box and return it to the uninitialized white state. To create the DELETE request, the process is the same as prior, but this request will be named `Delete color`. Make sure that you indicate we are doing a DELETE request in the dropdown menu in the route bar. The URL for this request will be `{{url}}delete/boxNumber`. Therefore, if you want to delete the color from box 254, the request should look like: + + + + + The requests we added to Color Changer are just some of the basic essentials needed to use Postman with your APIs. Postman has many features that allow you to test the functionality of APIs that you can continue to explore. \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md index 88670144..b50b4139 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/8.md @@ -1,46 +1,46 @@ - - -# Generating Documentation - -Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. - -One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. - -#### Color Changer Collection: - -We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: - - - -Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. - -However, we want to add more details to our documentation. The easy way to do so would be to: - -* Click the **New** button -* Click **API Documentation** -* Click the **Select an existing collection** -* Click **Color Changer** - -Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. - -After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. - -The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. - -To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: - - - -Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. - - - -Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. - - - - - - - + + +# Generating Documentation + +Creating documentation is important when creating any project. The same principle applies to Postman collections. We want to create documentation for our collections for people who might want to use the collections in the future. The documentation will provide the user on the purpose and usage of the collection. + +One feature that Postman provides is that it will automatically generate some documentation for a collection. You can then go into the generated documentation and edit it to include more detail. We will be using Postman's Documenter to create documentation for the Color Changer collection. + +#### Color Changer Collection: + +We will walk through an example of generating documentation for our Color Changer collection. To generate the documentation, click the arrow next to the collection on the collection menu: + + + +Then simply click **View in web**. As you can see, Postman generates some documentation for our Color Changer collection. + +However, we want to add more details to our documentation. The easy way to do so would be to: + +* Click the **New** button +* Click **API Documentation** +* Click the **Select an existing collection** +* Click **Color Changer** + +Once you get to this window, you will notice that Postman provides default questions for you to make you documentation more informative. I recommend answering those questions on your own to make sure you understand the purpose of the Color Changer collection. + +After answering those questions, click **Save**. Postman will provide you with a link to the updated documentation. + +The automatically generated documentation has a section for each request we made. It provides the name, request URL, and an example response on the right side. However, we want to edit this documentation to provide more details. + +To do so, you must open a certain request on Postman. Then click the small arrow next to the requests name: + + + +Then click **Add a description**. This will allow you to add add detail to each request's documentation using Markdown. + + + +Here is some sample documentation for each request we created. I recommend filling out this documentation for each request, or create your own documentation. Also, note that the request URL is in a generic form; I recommend changing your request URL to a generic form for the documentation, or explain each part of your current URL below. Therefore, the user can easily understand each part of the request URL. + + + + + + + \ No newline at end of file diff --git a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md index 2cabe4d5..db5165df 100644 --- a/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md +++ b/Module_Postman/activities/Act3_Creating_Postman_Collections/9.md @@ -1,40 +1,40 @@ - - -# Importing API Collections - -Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. - -On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. - - - -Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: - - - -Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: - - - -If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: - - - -Now that you have your access token copied to your clipboard, let's authorize our request in Postman: - - - -Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. - -Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: - - - -Now if we click **Send**, our request should go through and the response should look something like: - - - - - -There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. - + + +# Importing API Collections + +Postman has a feature that allows you to import APIs from existing documentation. To demonstrate this feature, we will be using **Cisco DevNet**, which can be found at https://explore.postman.com/team/ciscodevnet. + +On the link above, find **Webex Teams API**. To import this API into Postman, simply click the orange button to the right that says **Run in Postman**. It should open this collection in Postman. To understand the usage of this collection, you can click **View Documentation**. + + + +Since we'll be using the **Webex Teams API**, let's open it in Postman and open the documentation. The API request we are going to use from this collection is the **Create a room (Teams)** POST request, which can be found here: + + + +Since we did not create this collection or API, we obviously do not know how to use the **Create a room** request; therefore, let's refer to the documentation we opened earlier. If we look for this request in the left menu bar, we can easily the find documentation for the request we're working with. Here's what the documentation for this request looks like: + + + +If you look under **HEADERS** you will notice that this request requires an access token to perform this request. To get this access token, you will need to sign up for a Cisco Webex account on the link in the documentation (https://developer.webex.com/endpoint-rooms-post.html). Once you log into your Webex account, it will give you an access token. You simply have to click the copy button on this screen: + + + +Now that you have your access token copied to your clipboard, let's authorize our request in Postman: + + + +Notice how I selected the Authorization Type to be **Bearer Token**. I chose Bearer Token because the documentation indicated that the Authorization type is **Bearer**. + +Now that we've authenticated our request, we can send a **Create a room (Teams)** POST request. From the documentation, you may have noticed that our request data will be in the request Body in JSON format. Therefore, let's go to the **Body** tab in Postman and change the **"title"** of our new room to the value **"Chat Room"**: + + + +Now if we click **Send**, our request should go through and the response should look something like: + + + + + +There we go! We have now imported an API Collection into our Postman collections and used the documentation to send a request to the Cisco Webex API and received a response. + From a6af7333cbcd6fb1eae228d64d8a1cd85ae66924 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Sat, 22 Feb 2020 19:01:38 -0800 Subject: [PATCH 14/23] As many issue fixes without having an account --- .../labs/Week 3/Democratic Debate Sentiment/1.md | 2 +- .../labs/Week 3/Democratic Debate Sentiment/11.md | 3 ++- .../labs/Week 3/Democratic Debate Sentiment/112.md | 2 ++ .../labs/Week 3/Democratic Debate Sentiment/113.md | 4 +++- .../labs/Week 3/Democratic Debate Sentiment/12.md | 4 +--- .../labs/Week 3/Democratic Debate Sentiment/121.md | 10 +++++++++- .../labs/Week 3/Democratic Debate Sentiment/2.md | 4 +++- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md index f91ec835..bd409861 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/1.md @@ -1,4 +1,4 @@ -# Introduction + With the wealth of information at our disposal, American politics have increasingly become a game of misinformation and narrative twisting. To win elections, often times it doesn't matter what political candidates actually do or say, but how candidates can control the narrative surrounding their campaigns, and what the American people think of their candidates. diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md index 28c6697a..20e2f2c8 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/11.md @@ -2,4 +2,5 @@ The Twitter developer application process starts here, please complete the form. -![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) \ No newline at end of file +![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md index 20e2f2c8..7c1b766b 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/112.md @@ -2,5 +2,7 @@ The Twitter developer application process starts here, please complete the form. +As you are most likely a student, click on the student option to begin. If another option is more relevant, click on that instead. + ![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md index 6f158b95..72fa16f4 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/113.md @@ -2,4 +2,6 @@ After finishing your application, confirm your email and your account should be processed and reviewed swiftly. -![img](https://lh4.googleusercontent.com/8BKvmctSfLQEKERSZIc9_3jKl7lnpkRJO3736TBuIkfwBzZhkZMmPL8hUnNjrCf27SqX1iZaHOv1RBrNfB2V1990cl9z35ojA-RjoDnN0vgn5XWuDhwMjpbbhHLj5J1qcuq4M2KSC4g) \ No newline at end of file +![img](https://lh4.googleusercontent.com/8BKvmctSfLQEKERSZIc9_3jKl7lnpkRJO3736TBuIkfwBzZhkZMmPL8hUnNjrCf27SqX1iZaHOv1RBrNfB2V1990cl9z35ojA-RjoDnN0vgn5XWuDhwMjpbbhHLj5J1qcuq4M2KSC4g) + +After you have been approved, you will then be able to access the neccessary API keys. Be patient! This process can lasrt up to 2 bussiness weeks. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md index 11b31eef..c18e8829 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md @@ -2,11 +2,9 @@ When you have finished configuring your account, head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: -![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. +![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) -![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) - There is also an area to generate an access token and access secret token, please generate them and keep track of those as well. diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md index 07a09b03..d654daf1 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md @@ -2,5 +2,13 @@ Head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: -![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. +![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. + +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) + +![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) + +There is also an area to generate an access token and access secret token, please generate them and keep track of those as well. + + diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md index 7811e37d..298d2ba9 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md @@ -1,4 +1,6 @@ -# Authentication + + + Paste your keys and tokens in the allocated space. Then configure OAuth authentication with your consumer key and secret, set your access tokens and create a API object in `tweepy` to fetch tweets. From 70f9c9fc7288e5606f6aa68f3039f40af1e826e1 Mon Sep 17 00:00:00 2001 From: Rayna Ney Date: Sun, 23 Feb 2020 15:32:59 -0800 Subject: [PATCH 15/23] fixes issue #510 --- .../labs/Week 3/Democratic Debate Sentiment/12.md | 8 +++++--- .../labs/Week 3/Democratic Debate Sentiment/121.md | 2 +- .../labs/Week 3/Democratic Debate Sentiment/122.md | 8 +++++++- .../labs/Week 3/Democratic Debate Sentiment/123.md | 2 +- .../labs/Week 3/Democratic Debate Sentiment/2.md | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md index c18e8829..03be66ab 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/12.md @@ -2,9 +2,11 @@ When you have finished configuring your account, head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: -![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. +![qf76jiT](https://i.imgur.com/qf76jiT.png) -After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) +Click on “Create an app” and fill out app details. -There is also an area to generate an access token and access secret token, please generate them and keep track of those as well. +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use (these keys in the picture have been erased). The keys will be used to access Twitter's sentiment anlysis API and will be inserted into the starter code. + +There is also an area to generate an access token and access secret token, please generate them and keep track of those as well. They will be used in the starter code. diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md index d654daf1..8001cb9d 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/121.md @@ -2,7 +2,7 @@ Head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: -![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. +![qf76jiT](https://i.imgur.com/qf76jiT.png)Click on “Create an app”. Fill out app details; for the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md index 3f94fc25..42c3898b 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/122.md @@ -1,6 +1,12 @@ -In the creation of your app, fill out all the required information for your app details. For the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. +In the creation of your app, fill out all the required information for your app details. For the website URL field, you can input any website, we used https://bitproject.org. Leave the OAuth Callback URL, TOS and Privacy Policy fields blank. + + OAuth Callback URLs are used for providing directions on where a user should go after signing in with their Twitter credentials. They can even be used to redirect a user to a spcific page, which won't be neccessary for our lab. + +TOS stands for 'terms of service' which again, we don't need to specify here. + +Privacy Policy is similar to TOS, but would explain to users what the data collected from them would be used for. Since there will be no users other than yourself, it is not relevant. ![img](https://lh6.googleusercontent.com/wCWo0frQNm2aPD3Fv30kMC90DQDk880eGb1KTGrL5I7dOjis95GoVBI2zJJ3tacIz-0ux9HFpgAYeB4Ym_LC2OAPabCMRzGeiRtnVRUbKAqn_PdGyMLunDhZCo_h-4XIysnYivjUwnI) diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md index 1fef04ca..77467a79 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/123.md @@ -6,5 +6,5 @@ After creating your app, head to its “Keys and tokens” section, where you wi -Below the consumer API keys, there is also an area to generate an access token and access secret token, please generate them and keep track of those as well. +Below the consumer API keys, there is also an area to generate an access token and access secret token, please generate them and keep track of those as well. Remember, these keys will be used to access Twitter's sentiment anlysis API and will be inserted into the starter code. diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md index 298d2ba9..d9df4b71 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md @@ -4,4 +4,5 @@ Paste your keys and tokens in the allocated space. Then configure OAuth authentication with your consumer key and secret, set your access tokens and create a API object in `tweepy` to fetch tweets. -Bear in mind we will be using the `dem_search` dictionary for the rest of this lab. \ No newline at end of file +Bear in mind we will be using the `dem_search` dictionary for the rest of this lab. + From 589f890b137975a2b9a3f13a08360387e9b3f842 Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Sun, 23 Feb 2020 20:21:57 -0800 Subject: [PATCH 16/23] Twitter lab 3.1 1.md 11.md 111.md 112.md 113.md 2.md 21.md 211.md 3.md 31.md 311.md 32.md --- Module_Twitter_API/.DS_Store | Bin 6148 -> 6148 bytes .../Week 3/Airline Sentiment Analysis/1.md | 16 +++++++++--- .../Week 3/Airline Sentiment Analysis/11.md | 5 ++-- .../Week 3/Airline Sentiment Analysis/111.md | 2 +- .../Week 3/Airline Sentiment Analysis/112.md | 10 +++++++- .../Week 3/Airline Sentiment Analysis/113.md | 2 +- .../Week 3/Airline Sentiment Analysis/2.md | 12 ++++++--- .../Week 3/Airline Sentiment Analysis/21.md | 3 ++- .../Week 3/Airline Sentiment Analysis/211.md | 2 +- .../Week 3/Airline Sentiment Analysis/3.md | 24 ++++++++++++++++-- .../Week 3/Airline Sentiment Analysis/31.md | 13 +++++++--- .../Week 3/Airline Sentiment Analysis/311.md | 21 +++++++++------ .../Week 3/Airline Sentiment Analysis/32.md | 13 +++++----- .../Week 3/Airline Sentiment Analysis/33.md | 13 ++++++++++ .../Week 3/Airline Sentiment Analysis/4.md | 3 ++- 15 files changed, 104 insertions(+), 35 deletions(-) create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/33.md diff --git a/Module_Twitter_API/.DS_Store b/Module_Twitter_API/.DS_Store index efd0171a0474062b1b8db04cde21312584449c2d..073a6fd9cb0cd963f990a526c9f763bb086033aa 100644 GIT binary patch delta 319 zcmZoMXfc=|#>B)qu~2NHo+2a5!~pA!7aACWj2_+kr1Ii|q@4UD1_p*xNd-BX#U%y? z*BP0ZSyE#QK&XFurSb3Ff%o&t>xqpS2eWtOvtUQs;;T6n+0?(5HK=AXa;^L4WnjHTq_~U z!jQv|$dJTPTozoEmy@5D4$`sl;Axi4>>T_YzyR5J@H_Klei2;}kT#G}4GgEuU J4a^f8SOBY4Rbl`D delta 78 zcmZoMXfc=|#>CJzu~2NHo+2aD!~pBb1|lqz`I)pPOEdFqc4a=qvN?dcfoU^42R{c; g;buqX@640=MRYkC85kH205QX48y@M+F(ONt0V53)8~^|S diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md index 00aef389..6b894357 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/1.md @@ -1,14 +1,22 @@ -# Introduction + -For this lab, we will be conducting sentiment analysis on specific US airlines. To do this, we'll be gathering tweets referencing airlines using Twitter's API as well as the `tweepy` and `TextBlob` packages to determine whether generated tweets have a positive, neutral or negative attitude towards the airline in question. Then we'll graph that information, both in the form of a bar and line graph. +For this lab, we will be conducting sentiment analysis on specific US airlines. **Sentiment Analysis** is the analysis of language to identify emotions (positive, negative, etc). + +To perform sentiment analysis we'll be gathering tweets referencing airlines using Twitter's API as well as the `tweepy` and `TextBlob` packages to determine whether generated tweets have a positive, neutral or negative attitude towards the airline in question. Then we'll graph that information, both in the form of a bar and line graph. Twitter presence is an important point of emphasis for companies. Twitter users can quickly form a positive or negative opinion of company, depending on what users are tweeting pertaining to companies. Companies perform sentiment analysis frequently to gauge what Twitter's opinion of their company is, and what steps they can take to ensure a positive Twitter presence for their company. We'll conduct an elementary sentiment analysis that companies may conduct for this lab, this is an example of what you should be making by the end: ![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/AirlineSentimentExample.png) +To get started, you'll need to sign up for a Twitter API developer account. + -To start off, you'll need to make a new Twitter app and get four credentials for future use: consumer key, consumer token, access token and access secret token. +After you've signed up for the developer account you need to make a new Twitter app and get four credentials for future use: -Paste those credentials into the appropriate area in your starter code. +* consumer key +* consumer token +* access token +* access secret token +Paste those credentials into the appropriate area in your starter code. \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md index 28c6697a..ce744ff4 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/11.md @@ -1,5 +1,6 @@ -The Twitter developer application process starts here, please complete the form. +The following is the signup page for getting a Twitter developer account. Try to navigate to this page by yourself, and follow the steps for an *academic* account. + +![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) -![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md index 6e78cbed..0d68aa37 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/111.md @@ -1,6 +1,6 @@ -Proceed to Twitter Developer [here](https://developer.twitter.com/en/apps). Implementing sign-in with Twitter requires a Twitter developer account, so click “Apply”. +If you couldn't find it, the Twitter Developer application is found [here](https://developer.twitter.com/en/apps). Using the Twitter API requires an account, so you'll need to follow the steps, starting with clicking “Apply”. diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md index 20e2f2c8..58de33b3 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md @@ -1,6 +1,14 @@ -The Twitter developer application process starts here, please complete the form. +The Twitter developer application process starts at this page, please complete the form. Once you click 'student', proceed to the rest of the Application. + + + +When you're prompted to explain your use, you can explain that you'll be using Twitter to perform sentiment analysis for learning purposes. + + + +You will also be analyzing Twitter data, you can say this is also part of the exercise. ![img](https://lh4.googleusercontent.com/bOVrW7NkR9zdzVGR5Wpn4blHLWwsbRapfxYJdsFB2MXaEGDfD6GQ7REp8h42A3fSQmHDLtpAhsxEuSymYElifWq_dn4742hYwzfhO2nmZce6u5CtLhh8mJmBLSQ4KydLGG9NMWNp9F4) diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md index 6f158b95..78566499 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md @@ -1,5 +1,5 @@ -After finishing your application, confirm your email and your account should be processed and reviewed swiftly. +After finishing your application, confirm your email and your account should be processed and reviewed swiftly. ![img](https://lh4.googleusercontent.com/8BKvmctSfLQEKERSZIc9_3jKl7lnpkRJO3736TBuIkfwBzZhkZMmPL8hUnNjrCf27SqX1iZaHOv1RBrNfB2V1990cl9z35ojA-RjoDnN0vgn5XWuDhwMjpbbhHLj5J1qcuq4M2KSC4g) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md index 1d6ea5d0..dec38154 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md @@ -1,5 +1,11 @@ -# Authentication + -Paste your keys and tokens in the allocated space. Then configure OAuth authentication with your consumer key and secret, set your access tokens and create a API object in `tweepy` to fetch tweets. +The goal of this card is to set up authentication so your application can use Tweet information. You should: -Bear in mind we will be using the `us_search` dictionary for the rest of this lab. \ No newline at end of file +* Paste your keys and tokens in the starter code. +* Configure OAuth authentication with your consumer key and secret +* Set your access tokens and create a API object in `tweepy` to fetch tweets. + +Bear in mind we will be using the `us_search` dictionary for the rest of this lab. + +![image](https://images.pexels.com/photos/58639/pexels-photo-58639.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md index 77cae357..a29a2b09 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/21.md @@ -3,6 +3,7 @@ Paste your keys and tokens in the allocated space. You'll want to authenticate in three steps: 1. Configure OAuth authentication with your consumer key and secret with the `OAuthHandler(consumer_key, consumer_secret)` call. This should create an `auth` object -2. Set your access tokens with `auth.set_access_token()`. +2. Set your access tokens with `auth.set_access_token()` 3. Create a API object in `tweepy` to fetch tweets: `tweepy.API(auth, wait_on_rate_limit=True)` +![image](https://images.pexels.com/photos/46148/aircraft-jet-landing-cloud-46148.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md index e2315f0b..e2aa9472 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md @@ -1,4 +1,4 @@ - +j Remember all those credentials you generated? Paste them appropriately in the starter code. diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md index 5dbfd358..8168a52d 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/3.md @@ -1,4 +1,24 @@ -# Producing Dataframes + -First, we'll have to complete the function `produce_dataframe()`. Please reference the description in the starter code. Bear in mind we provide what will be passed into the `search_query` parameter for you, and you are not allowed to change any function definition or given code. By the end, you should have a data frame with just the date and sentiment of each tweet found. +Now that our application is set up, we're going to produce a dataframe that stores two items: the data, and the sentiment of each tweet found. + + + +Complete the function `produce_dataframe(search_dict, num_tweets)`, with the following descriptions of the parameters: + +* `search_dict` - a dictionary that has a {key, value} pair in the items category. The `key` is the date you will be searching for, and the `value` is the name of the airline you will search for. +* `num_tweets` - the number of tweets in the search dictionary + + + +The function `produce_dataframe(search_dict, num_tweets)` should complete the following checklist: + +* Return a dataframe using the `pandas` library, the column names should be 'date', and 'sentiment'. Set rownames to 'positive', 'neutral', and 'negative.' +* Fill the returning dataframe with + + + +You are not allowed to change any function definition or code that was given to you. The end result should look like this: + +![image]() diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md index 4015328d..857614b8 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/31.md @@ -2,9 +2,16 @@ -Our end result is going to be a dataframe with columns for the date of tweet and sentiment behind the tweet. This dataframe will be used to set up the graph later. +In order to add items to the dataframe, we first need to create dataframe. We can use the `pandas` library to create a dataframe. -Firstly, make a empty dataframe `df` with 2 empty columns, and set the columns attribute to be `['date', 'sentiment']`. +The function we want to use is `pandas.Dataframe(arguments)`. Use the argument: -For your search query, use the `Cursor` object from `tweepy` to generate n number of tweets including each query. (n corresponds to the parameter `num_tweets` in this case.) +* `index` to set the rownames to 'positive', 'neutral', and 'negative.' +* `columns` to set the columnnames to `date` and `sentiment` + + + +If you run your code before inserting any data, your graph should look like this: + +![image]() diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md index 4e41893f..5932b831 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/311.md @@ -2,19 +2,24 @@ -We want a dataframe with the following structure: +We can create a `pandas` dataframe with the function `pd.DataFrame()`. If we want a dataframe with the following structure (it currently has : +| | Airline_0 | Airline_1 | ... | +| -------- | --------- | --------- | ---- | +| positive | ... | ... | ... | +| neutral | ... | ... | ... | +| negative | ... | ... | ... | +We need the arguments: -| | Airline_0 | Airline_1 | ... | -| -------- | --------------- | --------------- | ---- | -| positive | 321 | 23 | ... | -| neutral | 76 | 32 | ... | -| negative | \# example data | \# example data | ... | +* `data` - this argument is defaulted to None, we define it to an explicit `[]` +* `Index` - We'll set this to a list of []'positive', 'neutral', 'negative'] -Our dataframe `df` will do the trick: +Our final code looks like: -``` +```python df = pd.DataFrame([], index=['positive', 'neutral', 'negative']) ``` +Now we need to get the tweets from the cursor object + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md index 95d57622..ed653a2d 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/32.md @@ -1,15 +1,14 @@ - + -In our `Cursor` object is a list of tweets with our search query. +Now that we've created our Dataframe, we need to fill our dataframe. Recall the parameter `search_dict` is a dictionary that has a {key, value} pair in the items category. The `key` is the date you will be searching for, and the `value` is the name of the airline you will search for. -Iterate through this cursor object and find whether its sentiment is positive, neutral or negative. -* You'll have to use `TextBlob` as well as the `sentiment.polarity` attribute. -Keep track of a list that will contain the sentiment ratings 'positive', 'neutral' or 'negative'. For each tweet, make sure you append the tweet's sentiment. +After producing the dataframe you should iterate through the `search_dict` and call the `tweepy.Cursor()` object to get the tweets with the search query. -When done iterating through the tweets, index the dataframe so that the sentiment data shows up in your dataframe. -The function should return `df`. \ No newline at end of file + +![image]() + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/33.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/33.md new file mode 100644 index 00000000..69b0311c --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/33.md @@ -0,0 +1,13 @@ + + +Now that we've got the tweets, we need to iterate through the tweets to find the sentiments. + + + +We also want to keep track of how many of each sentiments you have. Make sure to initialize the number of sentiments of each 'positive', 'neutral' or 'negative' first. + + + +You need to use the `TextBlob` module to get the `sentiment.polarity` attribute. For each item in the Tweets we have, set the item in the dataframe date to the sentiment. + +![image]() \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md index ddaa8d8b..b634e8b6 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md @@ -4,4 +4,5 @@ Now that we have our raw dataframe of dates and sentiments, we need to calculate Set up *one* dataframe that contains all of that data. This is what your dataframe should look like: -![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/Airline_DF.PNG) \ No newline at end of file +![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/Airline_DF.PNG) + From f12bc6c2ef672cd46daf6b6752fd0fdc0b69999e Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Sun, 23 Feb 2020 22:24:50 -0800 Subject: [PATCH 17/23] gitignore Node Week 2 --- .gitignore | 2 +- .../activities/Act12_Intro to NLP/.11.html.icloud | Bin 157 -> 0 bytes 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/.11.html.icloud diff --git a/.gitignore b/.gitignore index 0fa494df..7b1c8489 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ - +Node_Week_2 Module4_Labs/.DS_Store Module4_Labs/Lab2_Doubly_Linked_List/.DS_Store Module4_Labs/Lab3_File_System/.DS_Store diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/.11.html.icloud b/Module_Twitter_API/activities/Act12_Intro to NLP/.11.html.icloud deleted file mode 100644 index d79aeaba876df9759b1984ce93e3850965f48550..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 157 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFa6?1AjFQ|OAqJD&tat$#tm=YN(@S#_i#YgY^u2<@8Nh&%5kfPtLunXQ F1_1i#DP8~o From 57a041854a3b80e919951f3e30ba9b04709c553f Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Sun, 23 Feb 2020 22:26:00 -0800 Subject: [PATCH 18/23] gitignore Node Week 2 --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7b1c8489..756a9ff2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -Node_Week_2 +/Node_Week_2 Module4_Labs/.DS_Store Module4_Labs/Lab2_Doubly_Linked_List/.DS_Store Module4_Labs/Lab3_File_System/.DS_Store From 4d920673f26fd640485503cef1de1b6621f0168b Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Wed, 26 Feb 2020 00:15:14 -0800 Subject: [PATCH 19/23] 11.md for temporary git revert --- .../activities/Act12_Intro to NLP/11.md | 21404 ++++++++++++++++ 1 file changed, 21404 insertions(+) create mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/11.md diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/11.md b/Module_Twitter_API/activities/Act12_Intro to NLP/11.md new file mode 100644 index 00000000..676a1a12 --- /dev/null +++ b/Module_Twitter_API/activities/Act12_Intro to NLP/11.md @@ -0,0 +1,21404 @@ + + +Natural Language Processing (NLP) Tutorial with Python & NLTK - YouTube + + +/* Most common used flex styles*/ + + + +/* Basic flexbox reverse styles */ + + + +/* Flexbox alignment */ + + + +/* Non-flexbox positioning helper styles */ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+
+ + + Back + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + +
+ + +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + + + + + + + + + + +
+ +
+ +
+ +
+ +
+
+
+
+
+
+ +
+
+ +
+
+ + +
+ +
+
+
+ + +
+ + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+

Natural Language Processing (NLP) Tutorial with Python & NLTK

52,710 views52K views
Sep 27, 2018
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+
+ +
+ + + + + +
+ + + +
+ + + + + + + + + + +
+ +
+
1.61M subscribers
+ + + Subscribe + + + +
+ +
+ +
This video will provide you with a comprehensive and detailed knowledge of Natural Language Processing, popularly known as NLP. You will also learn about the different steps involved in processing the human language like Tokenization, Stemming, Lemmatization and more. Python, NLTK, & Jupyter Notebook are used to demonstrate the concepts. + +This tutorial was developed by Edureka. + +🔗NLP Certification Training: https://goo.gl/kn2H8T + +🔗Subscribe to the Edureka YouTube channel: https://www.youtube.com/user/edurekaIN + +🔗Edureka Online Training: https://www.edureka.co/ + +-- + +Learn to code for free and get a developer job: https://www.freecodecamp.org + +Read hundreds of articles on programming: https://medium.freecodecamp.org + +And subscribe for new videos on technology every day: https://youtube.com/subscription_cent...
+
+ + + + + + + +
+
+
+
+ + + + + + + +
+ +
+
+
+ + + + + + +
+
+
+
+
+ +
+
+ + + + + + + +
+
+
+ + + +
+ + + + +
+
+
+ +
+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
\ No newline at end of file From a3a500d5931d6d1e9db6bc908db93cd272264f9f Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Sun, 1 Mar 2020 21:41:20 -0800 Subject: [PATCH 20/23] Updated 4.md, 41.md, 42.md, 123.md, 211.md, 212.md, 213.md, Added README.md files for Lab 3.1 and 3.2 --- .../Act12_Intro to NLP/.11.md.icloud | Bin 0 -> 155 bytes .../activities/Act12_Intro to NLP/11.md | 21404 ---------------- .../Week 3/Airline Sentiment Analysis/112.md | 2 +- .../Week 3/Airline Sentiment Analysis/113.md | 2 +- .../Week 3/Airline Sentiment Analysis/121.md | 2 +- .../Week 3/Airline Sentiment Analysis/123.md | 13 +- .../Week 3/Airline Sentiment Analysis/2.md | 5 +- .../Week 3/Airline Sentiment Analysis/211.md | 23 +- .../Week 3/Airline Sentiment Analysis/212.md | 15 +- .../Week 3/Airline Sentiment Analysis/213.md | 8 - .../Week 3/Airline Sentiment Analysis/4.md | 12 +- .../Week 3/Airline Sentiment Analysis/41.md | 11 + .../Week 3/Airline Sentiment Analysis/411.md | 18 + .../Week 3/Airline Sentiment Analysis/412.md | 21 + .../Week 3/Airline Sentiment Analysis/42.md | 9 + .../Airline Sentiment Analysis/README.md | 20 + .../starter_code.py | 28 + .../Week 3/Democratic Debate Sentiment/2.md | 2 - .../Democratic Debate Sentiment/README.md | 20 + 19 files changed, 177 insertions(+), 21438 deletions(-) create mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/.11.md.icloud delete mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/11.md delete mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/41.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/README.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/starter_code.py create mode 100644 Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/README.md diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/.11.md.icloud b/Module_Twitter_API/activities/Act12_Intro to NLP/.11.md.icloud new file mode 100644 index 0000000000000000000000000000000000000000..c7e27c75f0be324cf4eeee5eb32a20e55f4be391 GIT binary patch literal 155 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFP(wq#+!P@OliaL$0U4~Sf>P5 - -Natural Language Processing (NLP) Tutorial with Python & NLTK - YouTube - - -/* Most common used flex styles*/ - - - -/* Basic flexbox reverse styles */ - - - -/* Flexbox alignment */ - - - -/* Non-flexbox positioning helper styles */ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
-
-
- - - Back - - - - - - - - - - -
-
- - -
- - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
- - - -
- - -
- -
-
-
- -
- -
-
-
- -
-
- - - - - - - - - - - -
- -
- -
- -
- -
-
-
-
-
-
- -
-
- -
-
- - -
- -
-
-
- - -
- - -
-
-
-
-
-
-
-
-
-
-
- -
-
-

Natural Language Processing (NLP) Tutorial with Python & NLTK

52,710 views52K views
Sep 27, 2018
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
- -
-
-
-
- -
-
-
- -
-
- -
- - - - - -
- - - -
- - - - - - - - - - -
- -
-
1.61M subscribers
- - - Subscribe - - - -
- -
- -
This video will provide you with a comprehensive and detailed knowledge of Natural Language Processing, popularly known as NLP. You will also learn about the different steps involved in processing the human language like Tokenization, Stemming, Lemmatization and more. Python, NLTK, & Jupyter Notebook are used to demonstrate the concepts. - -This tutorial was developed by Edureka. - -🔗NLP Certification Training: https://goo.gl/kn2H8T - -🔗Subscribe to the Edureka YouTube channel: https://www.youtube.com/user/edurekaIN - -🔗Edureka Online Training: https://www.edureka.co/ - --- - -Learn to code for free and get a developer job: https://www.freecodecamp.org - -Read hundreds of articles on programming: https://medium.freecodecamp.org - -And subscribe for new videos on technology every day: https://youtube.com/subscription_cent...
-
- - - - - - - -
-
-
-
- - - - - - - -
- -
-
-
- - - - - - -
-
-
-
-
- -
-
- - - - - - - -
-
-
- - - -
- - - - -
-
-
- -
-
- - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
\ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md index 58de33b3..e8e76e21 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/112.md @@ -1,6 +1,6 @@ -The Twitter developer application process starts at this page, please complete the form. Once you click 'student', proceed to the rest of the Application. +The Twitter developer application process starts at this page, please complete the form. Once you click "student", proceed to the rest of the Application. diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md index 78566499..3265c1d6 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/113.md @@ -1,5 +1,5 @@ -After finishing your application, confirm your email and your account should be processed and reviewed swiftly. +After finishing your application, confirm your email and your account should be processed and reviewed swiftly. Finish up by checking your email! ![img](https://lh4.googleusercontent.com/8BKvmctSfLQEKERSZIc9_3jKl7lnpkRJO3736TBuIkfwBzZhkZMmPL8hUnNjrCf27SqX1iZaHOv1RBrNfB2V1990cl9z35ojA-RjoDnN0vgn5XWuDhwMjpbbhHLj5J1qcuq4M2KSC4g) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md index 07a09b03..3d3abcc6 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/121.md @@ -1,6 +1,6 @@ -Head back to Twitter Developer [here](https://developer.twitter.com/en/apps), your app menu should look like this: +Head back to Twitter Developer website [here](https://developer.twitter.com/en/apps), and your app menu should look like this: ![img](https://lh6.googleusercontent.com/c2Eey4CUXd9gi3LFLPvbpKpDr1_qNTyZGHMKngCAjZ_prK1rITeI7AnLtWPRr0v_gRIGIxbT6MQUl7GAQ8wq6Hx1_JuFZFOhcUaPPhbf8RPTSprIvtluuqKWf3LULkCqRP-1FaPrkAU)Click on “Create an app”. diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md index 1fef04ca..4e4adbf5 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/123.md @@ -1,6 +1,6 @@ -After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. Copy these keys for later use. (these keys in the picture have been erased) +After creating your app, head to its “Keys and tokens” section, where you will find an API key and API secret key. ![img](https://lh4.googleusercontent.com/fLq7LZu_w2JKb2HCFHptAT1Ln4Z00JNMNq47knue29sH5HzWCSWbx_o6xpSeT0qOytCI7CLF8HqTdxlRQ_wb4JC9x_TnvSYgr8Ssjd3BKZBThHii-CkInXZ5UHO8mFVZU2L2e6DwpoE) @@ -8,3 +8,14 @@ After creating your app, head to its “Keys and tokens” section, where you wi Below the consumer API keys, there is also an area to generate an access token and access secret token, please generate them and keep track of those as well. + + +Copy these keys into your starter code where the example is: + +```python +consumer_key = "Your key goes here!" +consumer_secret = "Your key goes here!" +access_token = "Your key goes here!" +access_token_secret = "Your key goes here! +``` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md index dec38154..4720ceb3 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/2.md @@ -2,10 +2,9 @@ The goal of this card is to set up authentication so your application can use Tweet information. You should: -* Paste your keys and tokens in the starter code. -* Configure OAuth authentication with your consumer key and secret +* Configure OAuth authentication with your consumer key and secret key * Set your access tokens and create a API object in `tweepy` to fetch tweets. -Bear in mind we will be using the `us_search` dictionary for the rest of this lab. +You'll be using the `us_search` dictionary provided in the starter code for the rest of this lab. ![image](https://images.pexels.com/photos/58639/pexels-photo-58639.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md index e2aa9472..8cac3743 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/211.md @@ -1,11 +1,22 @@ -j + -Remember all those credentials you generated? Paste them appropriately in the starter code. +We're now going to authenticate using our app credentials. ```python -consumer_key = 'xxx' -consumer_secret = 'xxx' -access_token = 'xxx' -access_token_secret = 'xxx' +auth = OAuthHandler(consumer_key, consumer_secret) ``` +The above line generates an authentication object using our consumer key and secret. + +```python +auth.set_access_token(access_token, access_token_secret) +``` + +This line enables access to our authentication object with our access token and access secret token. + + + +Setting the above tokens is telling the Twitter API that you are the one using the application! Great job! + +![image](https://images.pexels.com/photos/1309644/pexels-photo-1309644.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md index 0d30563d..b2fc0a15 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/212.md @@ -1,16 +1,15 @@ - + -We are now going to authenticate using our app credentials. Please look at the next two lines of code: +The `tweepy` package allows us to very easily use Twitter's API within a Python environment. The line below will give us an API object that will allow us to fetch tweets. ```python -auth = OAuthHandler(consumer_key, consumer_secret) +api = tw.API(auth, wait_on_rate_limit=True) ``` -This line generates an authentication object using our consumer key and secret. +We're setting up our `api` object to use the authentication object `auth` we set up just before this. + -```python -auth.set_access_token(access_token, access_token_secret) -``` -This line enables access to our authentication object with our access token and access secret token. +The Twitter API has a limit of how many times you can request for an hour. The `wait_on_rate_limit` parameter is telling our Twitter request object to automatically wait for the rate limit to refresh for the hour. +![image](https://images.pexels.com/photos/1157255/pexels-photo-1157255.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md deleted file mode 100644 index e7466b3c..00000000 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/213.md +++ /dev/null @@ -1,8 +0,0 @@ - - -The `tweepy` package allows us to very easily use Twitter's API within a Python environment. The line below will give us an API object that will allow us to fetch tweets. - -```python -api = tw.API(auth, wait_on_rate_limit=True) -``` - diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md index b634e8b6..e616ea28 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/4.md @@ -1,8 +1,14 @@ -# Set-up Dataframes for Graph + -Now that we have our raw dataframe of dates and sentiments, we need to calculate the total tweets and the percentage of positive/neutral/negative tweets per day. +We currently have a dataframe containing the dates and sentiments for the airlines we searched for. We now want to calculate the total tweets and the percentages of positive/neutral/negative tweets for a specific airline -Set up *one* dataframe that contains all of that data. This is what your dataframe should look like: + + +The goal for this card is to create a *new* dataframe that's columns are the dates of the tweets, and the rows are labeled `positive`, `neutral`, `negative`, and `total`. The rows `positive`, `neutral`, and `negative` will be the percentage of tweets across the day, and `total` will be an integer, the number of tweetsfor that day. + + + +To do this, choose just *one* airline whose data you will perform analysis on, and create a dataframe that looks like the one below: ![](https://projectbit.s3-us-west-1.amazonaws.com/darlene/labs/Airline_DF.PNG) diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/41.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/41.md new file mode 100644 index 00000000..b60fdcc0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/41.md @@ -0,0 +1,11 @@ + + +Our first step is to create a dataframe with the raw dates and sentiments for each tweets. You can follow this process: + +1. Pick an airline from the `search_dict` dictionary (we chose United Airlines!) and get the related tweets using the Twitter API. You can search for the tweet since the variable `date_since`, which has an already calculated value of 3 days ago. +2. Create the empty Time Series Dataframe. Name the columns `date`, and `sentiment`. +3. Fill the time series dataframe by analyzing each tweet. Like before, tweets should be categorized into `postive`, `neutral`, or `negative`. + +Once we've created the time series dataframe, we can create percentages of tweets from that! + +![image](https://images.pexels.com/photos/2033343/pexels-photo-2033343.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md new file mode 100644 index 00000000..b5e18318 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md @@ -0,0 +1,18 @@ + + +We can search for the tweets related to an airline the same way we did before. The only thing we're changing here is we're picking on airline to search for instead of all of the airlines in the search dictionary. + +```python +tweets = tw.Cursor(api.search, + q="united airlines", + lang="en", + since=date_since).items(1000) +``` + +Again, we're getting a list of tweets through the Tweepy cursor object. + + + +In the background, the Tweepy cursor object is creating a loop that uses your API keys to get up to 1000 tweets as we set it with the parameter. + +![image](https://images.pexels.com/photos/1154619/pexels-photo-1154619.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md new file mode 100644 index 00000000..a1dfa588 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md @@ -0,0 +1,21 @@ +```python +text_create = [] +text_sentiment = [] +time_series_df = pd.DataFrame(pd.np.empty((0, 2))) +time_series_df.columns = ['date', 'sentiment'] + +for t in tweets: + text_create.append(t.created_at) + analysis = TextBlob(t.text) + + if analysis.sentiment.polarity > 0: + text_sentiment.append('positive') + elif analysis.sentiment.polarity == 0: + text_sentiment.append('neutral') + else: + text_sentiment.append('negative') + +time_series_df['date'] = text_create +time_series_df['sentiment'] = text_sentiment +``` + diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md new file mode 100644 index 00000000..a3a38400 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md @@ -0,0 +1,9 @@ + + +Now that we have our time series dataframe with each tweet and it's corresponding sentiment, we can create a dataframe with the percentages of each tweet per day. Try this process: + +1. Create the dataframe. The dataframe columns should be each day since `date_since`, and the row names should be `positive`, `neutral`, `negative`, and `total`. +2. Calculate the total number of tweets for each day. The numbers will be in the row `total`. +3. Calculate the percentage of `positive`, `neutral`, and `negative` for each day. + +![image](https://images.pexels.com/photos/1089306/pexels-photo-1089306.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/README.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/README.md new file mode 100644 index 00000000..f9c64055 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/README.md @@ -0,0 +1,20 @@ +# Activity/Lab Name + +Airline Sentiment Analysis + +# Long Summary + +Students will use the `tweepy` and `textblob` Python modules to utilize the Twitter API and perform sentiment analysis on tweets about airlines. Students will then use Python modules `pandas` and `matplotlib` to make a dataframe and graph the information appropriately. + +# Short Summary + +Students will use the Twitter API to analyze sentiments about airline tweets + +# Criteria + +1. How would you use a Tweepy cursor object to get Tweets from the Twitter API? +2. What's the difference between a time series dataframe and a regular dataframe? + +# Difficulty + +Medium diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/starter_code.py b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/starter_code.py new file mode 100644 index 00000000..16163c8a --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/starter_code.py @@ -0,0 +1,28 @@ +# Import necessary modules +import os +import tweepy as tw +import pandas as pd +import numpy as np +import matplotlib.pyplot as plt +from scipy import stats +from textblob import TextBlob +from tweepy import OAuthHandler +from IPython.display import display, HTML + +# 1.md and 2.md +consumer_key = "Your key goes here!" +consumer_secret = "Your key goes here!" +access_token = "Your key goes here!" +access_token_secret = "Your key goes here!" + +# Search dictionary to pass into produce_dataframe() as airlines to search for. DO NOT EDIT! +search_dict = {"Spirit Airlines": "#spiritairlines","JetBlue": "#jetblue", "Frontier Airlines": "frontier airlines", + "Delta": "delta airlines", "United": "united airlines", "Southwest": "southwest airlines", "American": + "american airlines" + } + +# The date to search from +date_since = "This date should be five days from now!" +d = datetime.datetime.today() +print(d) +# Check that the tweepy object is working! diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md index d9df4b71..bc1c754e 100644 --- a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/2.md @@ -1,5 +1,3 @@ - - Paste your keys and tokens in the allocated space. Then configure OAuth authentication with your consumer key and secret, set your access tokens and create a API object in `tweepy` to fetch tweets. diff --git a/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/README.md b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/README.md new file mode 100644 index 00000000..510698a9 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Democratic Debate Sentiment/README.md @@ -0,0 +1,20 @@ +# Activity/Lab Name + +Democratic Debate Sentiment + +# Long Summary + +Students will use the `tweepy` and `textblob` Python modules to utilize the Twitter API and perform sentiment analysis on tweets about the Democratic Debates. Students will then use Python modules `pandas` and `matplotlib` to make a dataframe and graph the information appropriately. + +# Short Summary + +Students will use the Twitter API to analyze sentiments about Democratic Debate tweets + +# Criteria + +1. How would you use a Tweepy cursor object to get Tweets from the Twitter API? +2. What's the difference between a time series dataframe and a regular dataframe? + +# Difficulty + +Medium From 72db81806bebe9595cdbf4a19a67fdf7fc779866 Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Sun, 1 Mar 2020 21:46:14 -0800 Subject: [PATCH 21/23] Readd 11.html --- .gitignore | 1 + .../Act12_Intro to NLP/.11.md.icloud | Bin 155 -> 0 bytes .../activities/Act12_Intro to NLP/11.html | 21404 ++++++++++++++++ 3 files changed, 21405 insertions(+) delete mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/.11.md.icloud create mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/11.html diff --git a/.gitignore b/.gitignore index 756a9ff2..58d1fdc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +Module_Twitter_API/labs/Week\ 2/ /Node_Week_2 Module4_Labs/.DS_Store Module4_Labs/Lab2_Doubly_Linked_List/.DS_Store diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/.11.md.icloud b/Module_Twitter_API/activities/Act12_Intro to NLP/.11.md.icloud deleted file mode 100644 index c7e27c75f0be324cf4eeee5eb32a20e55f4be391..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 155 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFP(wq#+!P@OliaL$0U4~Sf>P5 + +Natural Language Processing (NLP) Tutorial with Python & NLTK - YouTube + + +/* Most common used flex styles*/ + + + +/* Basic flexbox reverse styles */ + + + +/* Flexbox alignment */ + + + +/* Non-flexbox positioning helper styles */ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+
+ + + Back + + + + + + + + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + +
+ + +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + + + + + + + + + + +
+ +
+ +
+ +
+ +
+
+
+
+
+
+ +
+
+ +
+
+ + +
+ +
+
+
+ + +
+ + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+

Natural Language Processing (NLP) Tutorial with Python & NLTK

52,710 views52K views
Sep 27, 2018
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+
+ +
+ + + + + +
+ + + +
+ + + + + + + + + + +
+ +
+
1.61M subscribers
+ + + Subscribe + + + +
+ +
+ +
This video will provide you with a comprehensive and detailed knowledge of Natural Language Processing, popularly known as NLP. You will also learn about the different steps involved in processing the human language like Tokenization, Stemming, Lemmatization and more. Python, NLTK, & Jupyter Notebook are used to demonstrate the concepts. + +This tutorial was developed by Edureka. + +🔗NLP Certification Training: https://goo.gl/kn2H8T + +🔗Subscribe to the Edureka YouTube channel: https://www.youtube.com/user/edurekaIN + +🔗Edureka Online Training: https://www.edureka.co/ + +-- + +Learn to code for free and get a developer job: https://www.freecodecamp.org + +Read hundreds of articles on programming: https://medium.freecodecamp.org + +And subscribe for new videos on technology every day: https://youtube.com/subscription_cent...
+
+ + + + + + + +
+
+
+
+ + + + + + + +
+ +
+
+
+ + + + + + +
+
+
+
+
+ +
+
+ + + + + + + +
+
+
+ + + +
+ + + + +
+
+
+ +
+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
\ No newline at end of file From 777eb4d5793d3dd03699b2ae8ca60174a8621eca Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Fri, 6 Mar 2020 12:28:33 -0800 Subject: [PATCH 22/23] match to master --- .../Act12_Intro to NLP/.11 2.html.icloud | Bin 0 -> 159 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/.11 2.html.icloud diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/.11 2.html.icloud b/Module_Twitter_API/activities/Act12_Intro to NLP/.11 2.html.icloud new file mode 100644 index 0000000000000000000000000000000000000000..d0d41e14d1ace2a50a5c54bf4451911927fc2046 GIT binary patch literal 159 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFNJB#fBfX50+#DeWliaL$0U4|+gHqE=a}tX<_+|9HLLwQ!fRPbGGq6Kx H7*zoPNSP_P literal 0 HcmV?d00001 From 971371df4dd768bb34176393d7128765e0b37f3b Mon Sep 17 00:00:00 2001 From: Nathaniel Kong Date: Sun, 8 Mar 2020 20:17:59 -0700 Subject: [PATCH 23/23] Updated cards related to 4.md --- .../Act12_Intro to NLP/.11 2.html.icloud | Bin 159 -> 0 bytes .../Week 3/Airline Sentiment Analysis/411.md | 14 +++--- .../Week 3/Airline Sentiment Analysis/412.md | 24 ++++------ .../Week 3/Airline Sentiment Analysis/413.md | 43 ++++++++++++++++++ .../Week 3/Airline Sentiment Analysis/42.md | 2 +- .../Week 3/Airline Sentiment Analysis/421.md | 30 ++++++++++++ .../Week 3/Airline Sentiment Analysis/422.md | 16 +++++++ .../Week 3/Airline Sentiment Analysis/423.md | 23 ++++++++++ 8 files changed, 130 insertions(+), 22 deletions(-) delete mode 100644 Module_Twitter_API/activities/Act12_Intro to NLP/.11 2.html.icloud create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/413.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/421.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/422.md create mode 100644 Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/423.md diff --git a/Module_Twitter_API/activities/Act12_Intro to NLP/.11 2.html.icloud b/Module_Twitter_API/activities/Act12_Intro to NLP/.11 2.html.icloud deleted file mode 100644 index d0d41e14d1ace2a50a5c54bf4451911927fc2046..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 159 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?5QFNJB#fBfX50+#DeWliaL$0U4|+gHqE=a}tX<_+|9HLLwQ!fRPbGGq6Kx H7*zoPNSP_P diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md index b5e18318..96d25e05 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/411.md @@ -1,6 +1,10 @@ - + -We can search for the tweets related to an airline the same way we did before. The only thing we're changing here is we're picking on airline to search for instead of all of the airlines in the search dictionary. +We can search for the tweets related to an airline the same way we did before, but no we're going to choose one airline to search for instead of all of the airlines in the search dictionary. We've picked United Airlines in our example, but you can choose from any of the other ones in the search dictionary. + + + +The first thing we should do is create our twitter cursor object like we did before. The statement below is creating the cursor object that will stop at 1000 tweets and get tweets since three days ago. ```python tweets = tw.Cursor(api.search, @@ -9,10 +13,6 @@ tweets = tw.Cursor(api.search, since=date_since).items(1000) ``` -Again, we're getting a list of tweets through the Tweepy cursor object. - - - -In the background, the Tweepy cursor object is creating a loop that uses your API keys to get up to 1000 tweets as we set it with the parameter. +Now that we have `tweets` , our cursor object, we need to actually create a loop for the tweepy object to collect the tweets for us. The Tweepy cursor object in the background will get 1000 tweets using your API keys. ![image](https://images.pexels.com/photos/1154619/pexels-photo-1154619.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md index a1dfa588..2653f25e 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/412.md @@ -1,21 +1,17 @@ + + +Since we've got our Tweepy cursor object, we should create a dataframe to read the tweets into. Below is an empty dataframe with the columns titled `date` and `sentiment`. + ```python -text_create = [] -text_sentiment = [] time_series_df = pd.DataFrame(pd.np.empty((0, 2))) time_series_df.columns = ['date', 'sentiment'] +``` -for t in tweets: - text_create.append(t.created_at) - analysis = TextBlob(t.text) - - if analysis.sentiment.polarity > 0: - text_sentiment.append('positive') - elif analysis.sentiment.polarity == 0: - text_sentiment.append('neutral') - else: - text_sentiment.append('negative') +We'll also need two lists, one for the date, and one for the corresonding sentiment. Let's call these `text_create` (for dates) and `test_sentiment` (for sentiments). -time_series_df['date'] = text_create -time_series_df['sentiment'] = text_sentiment +```python +text_create = [] +text_sentiment = [] ``` +![image](https://images.pexels.com/photos/36983/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/413.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/413.md new file mode 100644 index 00000000..f1fa15a0 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/413.md @@ -0,0 +1,43 @@ + + +Now that everything is set up, let's get our tweets and their corresponding sentiments. We should loop through all of the tweets the cursor object will get. + +```python +for t in tweets: + # analyze our tweets here! +``` + +First, let's get the date the tweet was created: + +```python +for t in tweets: + text_create.append(t.created_at) +``` + +Above we're adding to the `text_create` list the time the date was created at. + +Next we should get the sentiment of the tweet. We can access this using `t.text` and analyze it using `Textblob()`. The *polarity* of the analysis is what we want to access, and this can be positive if >0, neutral if 0, and negative if <0. + +```python +for t in tweets: + text_create.append(t.created_at) + analysis = TextBlob(t.text) + + if analysis.sentiment.polarity > 0: + text_sentiment.append('positive') + elif analysis.sentiment.polarity == 0: + text_sentiment.append('neutral') + else: + text_sentiment.append('negative') +``` + +Finally, our lists are full of all the tweets and their sentiments! Let's add them into our dataframe. + +```python +time_series_df['date'] = text_create +time_series_df['sentiment'] = text_sentiment +``` + +Great, now all you need is to conver this raw dataframe into a different dataframe with percentages of each kind of sentiment for each day! + +![image](https://images.pexels.com/photos/127905/pexels-photo-127905.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md index a3a38400..82897da8 100644 --- a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/42.md @@ -1,6 +1,6 @@ -Now that we have our time series dataframe with each tweet and it's corresponding sentiment, we can create a dataframe with the percentages of each tweet per day. Try this process: +Now that we have our time series dataframe with each tweet and it's corresponding sentiment, we can create a different dataframe with the percentages of each tweet per day. Try this process: 1. Create the dataframe. The dataframe columns should be each day since `date_since`, and the row names should be `positive`, `neutral`, `negative`, and `total`. 2. Calculate the total number of tweets for each day. The numbers will be in the row `total`. diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/421.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/421.md new file mode 100644 index 00000000..6904e28a --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/421.md @@ -0,0 +1,30 @@ + + +Now that we've created the time series dataframe, we can create a dataframe that counts the percentages of `positive`, `neutral`, and `negative` tweets. The row at the bottom will be titled `total`, and will be the total amount of tweets for that day. First, we create the empty dataframe called `df`, created with `pd.Dataframe()` + +```python +df = pd.DataFrame() +``` + +Then, we'll fill in the dataframe with zeroes and and create the row/column names: + +```python +df = pd.DataFrame({dates[0]: [0.0, 0.0, 0.0, 0], + dates[1]: [0.0, 0.0, 0.0, 0], + dates[2]: [0.0, 0.0, 0.0, 0], + dates[3]: [0.0, 0.0, 0.0, 0]}, + index=['positive', 'neutral', 'negative', 'total']) +``` + +If you printed the dataframe, it would look like this: + +| | date1 | date2 | date3 | date4 | +| -------- | ----- | ----- | ----- | ----- | +| positive | 0.0 | 0.0 | 0.0 | 0.0 | +| neutral | 0.0 | 0.0 | 0.0 | 0.0 | +| negative | 0.0 | 0.0 | 0.0 | 0.0 | +| total | 0.0 | 0.0 | 0.0 | 0.0 | + +Great job! Next we'll fill up the data frame! + +![image](https://images.pexels.com/photos/1655985/pexels-photo-1655985.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/422.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/422.md new file mode 100644 index 00000000..28ea4c8d --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/422.md @@ -0,0 +1,16 @@ + + +Remember, `iterrows` get's an index and row for a dataframe and loops through it. So our process for each tweet in each row is to: + +1. Get the date +2. Add 1 to the count for the corresponding date and sentiment +3. Add one to the total for that row + +```python +for index, row in time_series_df.iterrows(): + date = str(row['date'].year) + '-0' + str(row['date'].month) + '-' + str(row['date'].day) + df.loc[row['sentiment'], date] += 1 + df.loc['total', date] += 1 +``` + +![image](https://images.pexels.com/photos/249581/pexels-photo-249581.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file diff --git a/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/423.md b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/423.md new file mode 100644 index 00000000..9d281364 --- /dev/null +++ b/Module_Twitter_API/labs/Week 3/Airline Sentiment Analysis/423.md @@ -0,0 +1,23 @@ + + +Our last step is to change the counts of each cell into percentages. This time, we'll iterate over a column instead of each row using `iteritems()`. colName will give us the column header, or the date in this case, and colData will give us each horizontal row header, so `positive`, `neutral`, `negative`, and `total`. To get the percentages instead of the counts we should divide the cell for a certain column by the total number, and multiply by 100 to get a percentage. Try this: + +```python +for colName, colData in df.iteritems(): + colData['positive'] = colData['positive'] / colData['total'] * 100 + colData['neutral'] = colData['neutral'] / colData['total'] * 100 + colData['negative'] = colData['negative'] / colData['total'] * 100 +``` + +This will give us unrounded numbers, lets use the `round()` function to get our numbers to the hundredths decimal place: + +```python +for colName, colData in df.iteritems(): + colData['positive'] = round(colData['positive'] / colData['total'] * 100, 2) + colData['neutral'] = round(colData['neutral'] / colData['total'] * 100, 2) + colData['negative'] = round(colData['negative'] / colData['total'] * 100, 2) +``` + +Great job! Next, we'll create a graph derived from the dataframe we just created! + +![image](https://images.pexels.com/photos/747079/pexels-photo-747079.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500) \ No newline at end of file