Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If you are skilled in Python. Please help me with this Python code and SQL code.

ID: 3605258 • Letter: I

Question

If you are skilled in Python. Please help me with this Python code and SQL code. If you need more info on what HW2 and HW3 were, just let me know and I will add more info. I really need help, idk whats actually being asked to do and how to tie in the hw2 & hw3 into this hw4.

Here are the company data files from HW2.

Here is the CSV file we created in hw3 named company-data.csv

Thank you!

Problem Description You need to answer questions about many different companies from many different sectors and these questions are awkward to answer using CSV files and Python code. Solution Description Create a database to hold company data, write a Python script that reads CSV files containing various company data and inserts that data into a database, and write SQL queries that answer various questions about the data in your database. Part 1: Create Company Database Write a database creation script named company schema.sql with create table statements that create a database with the following tables: company with fields ticker, name, sic, addri, addr, city, state, and ip o ticker should be the primary key. sic should be a foreign key referencing the sector table sector with fields sic, name sic should be the primary key. o name comes from the Sector field in the source CSV file. stock price with fields ticker, date, open, high, low, close, adj close, volume ( ticker , date) should be the (composite) primary key. To develop and test your work on the remainder of this assignment you should run your company-schema.sql script to create an SQLite database stored in a file such as company.db

Explanation / Answer

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

from __future__ import print_function

import tweepy

import json

import MySQLdb

from dateutil import parser

WORDS = ['#bigdata', '#AI', '#datascience', '#machinelearning', '#ml', '#iot']

CONSUMER_KEY = "KEY"

CONSUMER_SECRET = "SECRET"

ACCESS_TOKEN = "TOKEN"

ACCESS_TOKEN_SECRET = "TOKEN_SECRET"

HOST = "YOUR_DATABASE_HOST"

USER = "YOUR_DATABASE_USER"

PASSWD = "YOUR_DATABASE_PASSWORD"

DATABASE = "YOUR_DATABASE"

# This function takes the 'created_at', 'text', 'screen_name' and 'tweet_id' and stores it

# into a MySQL database

def store_data(created_at, text, screen_name, tweet_id):

    db=MySQLdb.connect(host=HOST, user=USER, passwd=PASSWD, db=DATABASE, charset="utf8")

    cursor = db.cursor()

    insert_query = "INSERT INTO twitter (tweet_id, screen_name, created_at, text) VALUES (%s, %s, %s, %s)"

    cursor.execute(insert_query, (tweet_id, screen_name, created_at, text))

    db.commit()

    cursor.close()

    db.close()

    return

class StreamListener(tweepy.StreamListener):   

    #This is a class provided by tweepy to access the Twitter Streaming API.

    def on_connect(self):

        # Called initially to connect to the Streaming API

        print("You are now connected to the streaming API.")

    def on_error(self, status_code):

        # On error - if an error occurs, display the error / status code

        print('An Error has occured: ' + repr(status_code))

        return False

    def on_data(self, data):

        #This is the meat of the script...it connects to your mongoDB and stores the tweet

        try:

           # Decode the JSON from Twitter

            datajson = json.loads(data)

           

            #grab the wanted data from the Tweet

            text = datajson['text']

            screen_name = datajson['user']['screen_name']

            tweet_id = datajson['id']

            created_at = parser.parse(datajson['created_at'])

            #print out a message to the screen that we have collected a tweet

            print("Tweet collected at " + str(created_at))

           

            #insert the data into the MySQL database

            store_data(created_at, text, screen_name, tweet_id)

       

        except Exception as e:

           print(e)

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)

auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

#Set up the listener. The 'wait_on_rate_limit=True' is needed to help with Twitter API rate limiting.

listener = StreamListener(api=tweepy.API(wait_on_rate_limit=True))

streamer = tweepy.Stream(auth=auth, listener=listener)

print("Tracking: " + str(WORDS))

streamer.filter(track=WORDS)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote