Best Python code snippet using pytest-django_python
weather-upload.py
Source: weather-upload.py
...26 data = response.json()27 return data28 except HTTPError as http_err:29 print(http_err)30def test_mydb(client, data, site):31 # Switch to the correct database32 client.switch_database('otherm')33 try:34 # Fields read from the file35 temp_c = round(data['properties']['temperature']['value'], 2)36 pres_kpa = round(data['properties']['barometricPressure']['value'], 2) / 100037 humi_per = round(data['properties']['relativeHumidity']['value'], 2)38 time = data['properties']['timestamp']39 print(f"temp_c: {temp_c}, pres_kpa: {pres_kpa}, humi_per: {humi_per}")40 formatted_data = [41 {42 "measurement": site,43 "fields": {44 "temperature_c": temp_c,45 "pressure_kpa": pres_kpa,46 "humidity_percent": humi_per,47 },48 "time": time49 }50 ]51 try:52 print(f"writing points to influx")53 client.write_points(formatted_data)54 print(f"write succeeded")55 except InfluxDBClientError as e:56 print(e)57 except:58 print("error")59def main():60 # File containing the station ids for the sites we would like to poll61 sites = pd.read_csv('./NWS_stations.csv', header=0)62 # Iterate through the stations and grab the JSON data63 for index, row in sites.iterrows():64 station_id = row['code']65 # Build the url for the request and then create the directory name66 nws_url = "https://api.weather.gov/stations/" + station_id + "/observations/latest?require_qc=true"67 # Get the data from the national weather service and write it to a file68 data = get_data(nws_url, "NWS", station_id)69 client = InfluxDBClient(host='influxdb', port=8086, username=os.environ.get('INFLUXDB_ADMIN_USER'), password=os.environ.get('INFLUXDB_ADMIN_PASSWORD'))70 test_mydb(client, data, station_id)71if __name__ == "__main__":72 main()...
learning(14)_SQL_PYTHON(3).py
Source: learning(14)_SQL_PYTHON(3).py
1import cx_Oracle2def Create_Table():3 dsn = cx_Oracle.makedsn("localhost",1521,'xe')4 db = cx_Oracle.connect('SCOTT','TIGER',dsn)5 cur = db.cursor()6 sql_cmd = "CREATE TABLE Test_mydb(id number, name varchar2(20))"7 cur.execute(sql_cmd)8 db.close() # ëë¹ êº¼ì¤ë¤.9def Select_all():10 dsn = cx_Oracle.makedsn("localhost", 1521, 'xe')11 db = cx_Oracle.connect('SCOTT', 'TIGER', dsn)12 cur = db.cursor()13 cur.execute("select * from Test_mydb")14 result = cur.fetchall()15 for row in result:16 print(str(row[0]) + " "+ row[1])17 cur.close()18 db.close()19def Insert_m():20 dsn = cx_Oracle.makedsn("localhost", 1521, 'xe')21 db = cx_Oracle.connect('SCOTT', 'TIGER', dsn)22 cur = db.cursor()23 cur.execute("insert into test_mydb values('1','python1')")24 cur.execute("insert into test_mydb values('2','python2')")25 cur.execute("insert into test_mydb values('3','python3')")26 cur.execute("insert into test_mydb values('4','python4')")27 db.commit()28 db.close()29if __name__ == '__main__':30 #Create_Table()31 Insert_m()...
learning(15)_SQL_PYTHON(4).py
Source: learning(15)_SQL_PYTHON(4).py
1import cx_Oracle2class OraDb1:3 def __init__(self): # ì°ê²°4 self.dsn = cx_Oracle.makedsn("localhost", 1521, 'xe')5 self.db = cx_Oracle.connect('SCOTT', 'TIGER', self.dsn)6 self.cur = self.db.cursor()7 def Insert_m(self):8 self.cur.execute("insert into test_mydb values('1','python1')") #ë³ì ì°¾ìì ì¸ê².9 self.db.commit()10 self.cur.close()11 self.db.close() #ì°½ì´ ë«ìëê¹ì§ í´ë¡ì¦ ìí기ë문ì ë©ìëë§ë¤ ë¤ DB를 ë«ê² í´ì¤ë¤.12 def Select_all(self):13 self.cur.execute("select * from Test_mydb")14 result = self.cur.fetchall()15 for row in result:16 print(str(row[0]) + " " + row[1])17 self.cur.close()18 self.db.close()19 def __del__(self): # ë«ê¸°20 pass21 #self.db.close()22if __name__ == '__main__':23 test = OraDb1()...
Check out the latest blogs from LambdaTest on this topic:
Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
If you are a web tester then somewhere down the road you will have to come across Selenium, an open-source test automation framework that has been on boom ever since its launch in 2004.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!