Skip to main content

Posts

Making a Geographic Heatmap with Python

Recent posts

Save Rendered Templates in Flask

 Flask:     We can return multiple types of responses using flask like HTTP Responses , XML responses and Templates responses. Consider the use case like you wanted to save html pages which are dynamically rendered    Packages required: 1. jinja2 2. Flask   Create a Folder structure:     Template        |-   image        |-   fonts        |-   js          index.html   index.html: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>{{name}}</h1> <p>{{address}}</p> </body> </html>     code: #imports from jinja2 import Environment , select_autoescape , FileSystemLoader #fetch the index.html file using the FilesystemLoader path = os . path . dirname ( os . path . abspath ( __file_...

Python package as Layer in AWS Lambda

 Layers in Lambda     Layers are useful for importing the libraries which not listed in aws. Consider you want to import pymysql lib for your RDS connection or pymongo for your Mongodb database connection, if you are not added them as layer these libraries are not available  Creating the layer: step1: Open your terminal and create a folder give a proper name   (lambda_pymysql_layer..) step2: change directory to lambda_pymysql_layer then create folder name should be python mkdir lambda_pymysql_layer cd lambda_pymysql_layer mkdir python   stpe3: pip3 install pymysql -t ./ (install your package in the current directory) step4: Then zip your folders step5: Zip the folder from python directory step6: import this zip in add files of lambda function step7: import pymysql

ReplicaSet In Mongodb

Replica Set      A replica set is a group of mongod instances that host the same data set. In a replica, one node is primary node that receives all write operations. All other instances, such as secondaries, apply operations from the primary so that they have the same data set. Creating the mongod instances: First we need to create a mongod isntance using below command. before creating the instance make a directory with any name ex: db1 and give this path in the below command Use any port you want  mongod --port 20017 --dbpath C:\Users\michel\db1\ --replSet rs0 Create a another mongod isntance using the different terminal by using the same command but give different path and port number is diffferent mongod --port 20018 --dbpath C:\Users\michel\db2\ --replSet rs0 Creating the mongo shell terminals: Now use the new terminal to open mongo terminal using below command mongo --port 20017 then initiate the replica set using be...

CommandLine Args In Python

 Command line args in Python :      When the program comes to Python , it's all about libraries .Argparser is the library used for the taking inputs from the command line. Here you can validate the arguments which are entered by the user without writing the another function to validate from the if conditions. suppose give a filename like cmdprocess.py You can give the expecting arguments like below cmdprocess.py --help      it will give the total arguments with respective commands to represent Required =True :           When the required is true. You have to enter the argument.   Type = function name:          Type is very useful to validate the input entered by the user. so that you can send a message like user need to enter the defined arguments only. This function always expects the input argument . Custom-Exceptions In Python:    There are multiple exception...

S3 Bucket events to trigger lambda function

 AWS Lambda:      It lets you run code without provisioning or managing servers. You pay only for the compute time you consume. With Lambda, you can run code for virtually any type of application or back-end service - all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app.       Creating a Lambda Function:   step1: select lambda service from services     step2:            1. Give appropriate function name          2. select runtime environment (i am working on python3.6)          3. click on change execution and select Create a new role from AWS                 ...

MQTT set up Flask

 MQTT Introduction: It is message broker which holds the data when ever a consumer will connected to the topic then he will receive the data . mqtt is a machine to machine message broker, mainly used in IOT application, the default port is 1883   Installation: sudo apt-get update sudo apt-get install mosquitto Command line execution: Producer mosquitto_pub -h 127.0.0.1 -t 'topic_name' -m '{'name':'Sony'}' Subscriber mosquitto_sub -h 127.0.0.1 -t 'topic_name' -h : it is the host address -t : topic name -m : message payload QOS in MQTT: QOS(quality of services) there are mainly 3 services are available in mqtt  qos=0 qos=1 qos=2 QOS (0,0): At most once service, publisher will send a message to broker at most once, the broker passes a message to subscriber one time