Commit eb79a92b by arun.uday

commi1

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (task7)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/task7.iml" filepath="$PROJECT_DIR$/.idea/task7.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import uvicorn
# starting the application
if __name__ == "__main__":
print("Fast API task")
uvicorn.run("scripts.services.receiver_app_services.py:app", host="127.0.0.1", port=8001, reload=True)
[path]
base_path = scripts/
sub_path = temp/
[file]
file_name_csv = MOCK_DATA.csv
file_name_json = data.json
import configparser
config = configparser.RawConfigParser()
config.read("conf/applications.conf")
# path
base_path = config.get("path", 'base_path')
sub_path = config.get("path", "sub_path")
# file name
file_name_csv = config.get("file", "file_name_csv")
file_name_json = config.get("file", "file_name_json")
full_path_csv = base_path + sub_path + file_name_csv
full_path_json = base_path + sub_path + file_name_json
def display_fetched_data(cursor):
# Fetch all the rows as a list of tuples
rows = cursor.fetchall()
# Iterate through the rows and print the data
for row in rows:
print(row)
import sqlite3
connection_db = sqlite3.connect('user_details.db')
import json
import pandas as pd
from scripts.database.mysqlite_connect import connection_db
from scripts.utilis.operations_db import SqliteOperations
def on_connect(client, m, c, rc):
print("Connected with result code " + str(rc))
client.subscribe("topic")
def on_message(m, c, msg):
payload_decoded = msg.payload.decode('utf-8')
json_data = json.loads(payload_decoded)
data_list = list(json_data.values())
frames = pd.DataFrame(data_list, index=None)
obj_db = SqliteOperations()
obj_db.create_db(connection_db)
obj_db.insert_db(connection_db, frames)
obj_db.fetch_data(connection_db, frames)
import paho.mqtt.client as mqtt
from fastapi import FastAPI
from scripts.services.connect_send_msg import on_connect, on_message
# This is the Subscriber
app = FastAPI()
@app.get("/")
def receiver():
client = mqtt.Client()
client.connect("192.168.0.220", 1883, 60)
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()
id,first_name,last_name,email,Address
1,Maurita,Helks,mhelks0@parallels.com,PO Box 3203
2,Prisca,Baxstar,pbaxstar1@whitehouse.gov,20th Floor
3,Camellia,Gallop,cgallop2@comsenz.com,5th Floor
4,Kingston,Keightley,kkeightley3@rediff.com,Suite 35
5,Suzie,Tredgold,stredgold4@myspace.com,PO Box 76402
6,Ade,Coonihan,acoonihan5@stanford.edu,Apt 376
7,Candida,Kobiela,ckobiela6@jiathis.com,10th Floor
8,Karee,Marty,kmarty7@auda.org.au,Suite 75
9,Granville,Weathey,gweathey8@bloglovin.com,2nd Floor
10,Letty,Brecher,lbrecher9@posterous.com,3rd Floor
11,Tam,Graal,tgraala@dmoz.org,Apt 525
12,Dusty,Causbey,dcausbeyb@drupal.org,Apt 1003
13,Kath,Chattey,kchatteyc@smugmug.com,Apt 1074
14,Rutter,Wattins,rwattinsd@hhs.gov,Room 1920
15,Simonette,Gledstane,sgledstanee@nytimes.com,20th Floor
16,Cassey,Gerrelt,cgerreltf@scribd.com,12th Floor
17,Paige,O'Henery,poheneryg@nature.com,Apt 1111
18,Tabbie,Trever,ttreverh@ask.com,20th Floor
19,Hoebart,Valder,hvalderi@tripod.com,5th Floor
20,Margie,Stollenbecker,mstollenbeckerj@fema.gov,Apt 531
21,Bobby,Beet,bbeetk@odnoklassniki.ru,20th Floor
22,Obie,Le Blanc,oleblancl@bravesites.com,Room 832
23,Alyosha,Ruffli,arufflim@bandcamp.com,Suite 14
24,Syman,Granger,sgrangern@bbb.org,PO Box 19521
25,Slade,Weller,swellero@livejournal.com,Room 1911
26,Robina,Rate,rratep@ask.com,Apt 917
27,Karon,Liveley,kliveleyq@tinypic.com,3rd Floor
28,Patty,McGeouch,pmcgeouchr@paginegialle.it,11th Floor
29,Osborn,Ferriday,oferridays@slashdot.org,Room 1474
30,Ellsworth,Dundin,edundint@wikispaces.com,PO Box 17827
31,Mitch,Stetson,mstetsonu@linkedin.com,Apt 603
32,Hardy,Swansbury,hswansburyv@google.it,Apt 1802
33,Nikolas,Telling,ntellingw@ocn.ne.jp,Room 148
34,Gladi,Florey,gfloreyx@dropbox.com,Suite 55
35,Adela,Overbury,aoverburyy@tinyurl.com,4th Floor
36,Evie,McFfaden,emcffadenz@scribd.com,Suite 88
37,Baldwin,Reaman,breaman10@booking.com,Suite 71
38,Beckie,Leadley,bleadley11@blogs.com,Apt 1592
39,Bendick,Kubes,bkubes12@latimes.com,Room 769
40,Huntlee,Mazzeo,hmazzeo13@columbia.edu,Apt 1564
41,Vally,Dzenisenka,vdzenisenka14@themeforest.net,PO Box 96195
42,Lethia,Bolden,lbolden15@yandex.ru,Suite 80
43,Odille,Chataignier,ochataignier16@slate.com,PO Box 73001
44,Cy,Wescott,cwescott17@reuters.com,17th Floor
45,Darnell,Jays,djays18@yellowbook.com,Room 1722
46,Mikael,Wickwar,mwickwar19@bloglines.com,Room 1780
47,Marguerite,McGahey,mmcgahey1a@1688.com,Room 243
48,Jessie,Gaskill,jgaskill1b@angelfire.com,Suite 98
49,Gardiner,Bestall,gbestall1c@cloudflare.com,17th Floor
50,Jo-ann,Rickett,jrickett1d@live.com,Room 903
51,Gavra,Moquin,gmoquin1e@quantcast.com,Room 1139
52,Dylan,Slewcock,dslewcock1f@trellian.com,Apt 1256
53,Danyette,Coolson,dcoolson1g@biglobe.ne.jp,Apt 452
54,Roderich,Ashworth,rashworth1h@163.com,Apt 1416
55,Hildagarde,Haucke,hhaucke1i@ox.ac.uk,Suite 7
56,Darlleen,Bearsmore,dbearsmore1j@google.com,Suite 43
57,Wilmette,Bedwell,wbedwell1k@weebly.com,Suite 65
58,Neville,Swapp,nswapp1l@ocn.ne.jp,Apt 1054
59,Norene,Kopacek,nkopacek1m@domainmarket.com,Suite 38
60,Aubert,Streeting,astreeting1n@cocolog-nifty.com,Suite 82
61,Katrine,Easson,keasson1o@bizjournals.com,Room 1306
62,Celle,Elgie,celgie1p@sciencedirect.com,16th Floor
63,Alvan,Curtin,acurtin1q@booking.com,16th Floor
64,Cornela,Roder,croder1r@google.pl,2nd Floor
65,Wanids,Dansie,wdansie1s@fc2.com,18th Floor
66,Kip,Fillon,kfillon1t@imgur.com,Suite 82
67,Holmes,Kidstoun,hkidstoun1u@usnews.com,Apt 17
68,Freddy,Featherstone,ffeatherstone1v@parallels.com,13th Floor
69,Gusella,Jodlkowski,gjodlkowski1w@chronoengine.com,Apt 515
70,Marietta,Circuit,mcircuit1x@nydailynews.com,18th Floor
71,Brander,Hackley,bhackley1y@drupal.org,Suite 91
72,Nikola,Hughes,nhughes1z@elegantthemes.com,Suite 34
73,Krisha,Aberkirder,kaberkirder20@blogs.com,Suite 70
74,Shina,Meriott,smeriott21@rakuten.co.jp,18th Floor
75,Debra,Sproat,dsproat22@wikia.com,Apt 1650
76,Dunc,Wallworke,dwallworke23@devhub.com,PO Box 58145
77,Rivalee,Gonnet,rgonnet24@oracle.com,Suite 97
78,Regine,Keling,rkeling25@edublogs.org,Room 1519
79,Ashla,Fair,afair26@ucla.edu,Apt 1213
80,Arabela,Theakston,atheakston27@nsw.gov.au,Apt 1277
81,Barney,Grimsdale,bgrimsdale28@reddit.com,PO Box 144
82,Lucho,Braunlein,lbraunlein29@cisco.com,PO Box 26380
83,Jania,Eldredge,jeldredge2a@bloglovin.com,Suite 3
84,Hector,Remer,hremer2b@va.gov,Suite 51
85,Hans,Cantrell,hcantrell2c@bbb.org,Apt 1834
86,Jacquelynn,Kuhne,jkuhne2d@unc.edu,PO Box 70594
87,Way,Moogan,wmoogan2e@chronoengine.com,PO Box 51805
88,Janenna,Costa,jcosta2f@symantec.com,Room 1115
89,Hermine,Bridywater,hbridywater2g@weibo.com,13th Floor
90,Claudette,Highman,chighman2h@ftc.gov,Room 1359
91,Reinhold,Bromehed,rbromehed2i@cargocollective.com,9th Floor
92,Katleen,Dohmer,kdohmer2j@naver.com,PO Box 73746
93,Kellen,Hull,khull2k@eepurl.com,Apt 1569
94,Chrotoem,Lorincz,clorincz2l@behance.net,PO Box 8905
95,Worth,Putton,wputton2m@qq.com,PO Box 91027
96,Luce,Lyford,llyford2n@nps.gov,Room 739
97,Van,Warre,vwarre2o@zimbio.com,Room 1771
98,Kikelia,Benardette,kbenardette2p@vkontakte.ru,PO Box 74859
99,Fabio,Grigoli,fgrigoli2q@plala.or.jp,Apt 1785
100,Rhodia,Batch,rbatch2r@alibaba.com,Room 1597
class SqliteOperations:
@staticmethod
def create_db(conn):
try:
conn.execute('''CREATE TABLE IF NOT EXISTS details
(ID INT PRIMARY KEY NOT NULL,
FIRSTNAME TEXT NOT NULL,
LASTNAME TEXT NOT NULL);''')
return conn
except Exception as e:
print(e)
@staticmethod
def insert_db(conn, frames):
try:
frames.to_sql('details', conn, if_exists='replace')
conn.commit()
except Exception as e:
print(e)
@staticmethod
def fetch_data(conn):
try:
# Create a cursor
cursor = conn.cursor()
# Execute a SELECT statement to fetch data from the "employees" table
cursor.execute("SELECT * FROM details")
return cursor
except Exception as e:
print(e)
\ No newline at end of file
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment