Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Created Workers #3

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion workers/DatabaseConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def data_get_and_insert(self, search_resp) :

if search_resp.status_code == 200 :

#convert text into a data object (dictionary) for Python
#convert text into a data object (dictionary) for Python
tweet_data = search_resp.json()

#Get data from Twitter API
Expand Down
7 changes: 4 additions & 3 deletions workers/ORMConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def twitter_conn() :
search_params = {
'q': 'Makeup',
'result_type': 'recent',
'count': 3
'count': 10
}

#Send request to Twitter API
Expand All @@ -40,6 +40,7 @@ def twitter_conn() :
def data_get_and_insert(search_resp, metadata, tweets, connection) :

id = None
print(search_resp.status_code)
if search_resp.status_code == 200 :

#convert text into a data object (dictionary) for Python
Expand All @@ -50,14 +51,14 @@ def data_get_and_insert(search_resp, metadata, tweets, connection) :
text = tweet['text']
time = tweet['created_at']
name = tweet['user']['screen_name']
print('FIRST DATA' , text +'\n'+ time +'\n'+ name )
print('FIRST DATA' , text +'\n'+ time +'\n'+ name + '\n')

#ORM query
query = tweets.insert().values(name = name , text = text , time = time).returning(tweets.c.id)
result = connection.execute(query)

else :
print('Result for' , search_url , 'is unsuccesful')
print('Request unsuccesful')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont commit changes in ur py file when the commit is about ENV vars in README


if __name__ == '__main__':
orm_config()
Expand Down
21 changes: 21 additions & 0 deletions workers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ Info about the endpoint of Twitter API https://developer.twitter.com/en/docs/twe
## Environment variables set up
- Create a .env file and input the variables
- Call dotenv library and os to get the desired variables
variables description :
1. BEARER_TOKEN
Token that consist of all kinds of character.
OAuth 2.0 generated from Account Token and Account Token Secret from Twitter developer page, Once these two tokens are available, use get_bearer_token.py to generate Bearer Token for the account
2. ACC_TOKEN
Token that consist of all kinds of character.
This token can be generated after user create an account and a new aplication in the developer page.
3. ACC_TOKEN_SECRET
Token that consist of all kinds of character.
This token can be generated after user create an account and a new aplication in the developer page.
4. USERNAME
consist of string/int that the user created in PostgreSQL
5. PASSWORD
consist of string/int that the user created in PostgreSQL
6. DB_NAME
consist of string/int that the user created in PostgreSQL
7. DB_PORT and DB_HOST
default value in PostgreSQL are DB_PORT = 5432 , DB_HOST = localhost
8. DATABASE_URL_ADDON
an URL for ORM endpoint of PostgreSQL that consist of
USERNAME:PASSWORD@HOST:PORT/DATABASE_NAME

## Connect to PostgreSQL server and queries
- start postgres server with psql -U <user> <database_name>
Expand Down