Posts

Showing posts from 2020

Heroku deploy web appliaction

 When deploying a python flask web application I got an error that at=error code=H14 desc=”No web processes running” method=GET path=”/” host=xxx.herokuapp.com request_id=xxx fwd=”xxx.xx.xx.x" dyno= connect= service= status=503 bytes= Solution: Check if you have Procfile in your project root folder and if present check if you have web: <command> present to start your application. The above solution solved my problem.

Sending message to Telegram Group, User or Bot using Python

In Programming world, most of the time while automating a system/tasks you need to send completion or timely notification about the status. Now a days the easiest way of notification is WhatsApp or Telegram as our SMS and email boxes are mostly flooded with spams. In this article we will try to explain about telegram automation using simple Python script. Install json and telegram package using pip package manager: pip install json pip install python-telegram-bot read token of your telegram bot and chat_id from json file telegram_credentials.json call notify_(message) function from the point in your script where you need to send notification and pass token and chat_id to it. import json import telegram def notify_(message): t_bot = telegram.Bot(token=token) t_bot.sendMessage(chat_id=chat_id, text=message) with open('./telegram_credentials.json', 'r') as keys_file: k = json.load(keys_file) token = k['telegram_token'] chat_id

Golden Crossover with MA strategy

Most of the fundamental investors believe in Buy and Hold strategy, but I think most of the retail fundament investors doesn't know when to exit. Also in most cases they get trapped when there is a sudden deterioration in the fundaments. So, for such investors, I believe below is a very good strategy and may save from huge draw-down. This strategy is purely for long term or positional investors. It is combination of two different strategies which are famous among swing or positional traders namely golden crossover (50/200) and 200 moving average. Strategy:  Open stock on a daily time frame chart, draw moving average indicators for 50 and 200 on the chart, these MA indicators will draw 50 days and 200 days moving average of stock. Now for buying the stock you need to see below two conditions: Stock should trade above 200 moving average line. Shorter moving average line should be above longer duration moving average, that means 50 ma line should be above 200 ma line. Similarly for ex

Read and print column names of Pandas dataframe

In your development and dealing with huge datasets you may need to read column names of data. Python has very powerful library called as pandas for data processing, pandas have very popular data structure named as Dataframe. There are many ways to get column names of dataframe in pandas library we below: import pandas as pd df = pd.DataFrame({'column1': [2, 4, 8, 0], 'column2': [6, 0, 0, 0], 'column3': [10, 2, 1, 8], 'column4': [14, 5, 32, 68]}) # print Dataframe print(df) # Column names as list print(list(df.columns)) # Column names print(df.columns.values) # iterating the columns for column in df.columns: print(column, end=' ') # using end argument to print all column values in single line. print() # Using toList() function print(df.columns.values.tolist()) Happy coding.

Read and Store data from csv file in Python

In your python development, there are many instances when you need to read some data from CSV or may need to store results (final or intermediate) to csv files, So in this article we will see some ways to read and store Pandas dataframe in csv files.   import pandas as pd df = pd.DataFrame({'column1': [2, 4, 8, 0], 'column2': [6, 0, 0, 0], 'column3': [10, 2, 1, 8], 'column4': [14, 5, 32, 68]}) df.to_csv("temp.csv", index=False) print(pd.read_csv("temp.csv")) # print Dataframe print(df) if you want to raed csv line by line then use csv package as below: import csv with open('temp.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: if line_count == 0: print(f'Column names are {", ".join(row)}') line_count += 1 else: pri

Store data in MySQL using Python : sample code

Store data in MYSQL in Python Many times in your python application you may need to store results or some data into relational database and MySQL is one of the most widely used relational database. In this post we are presenting you with a sample script to insert records in MySQL table.  In below example we will be using mysql connector python for demonstration. import mysql.connector from mysql.connector import Error from mysql.connector import errorcode try: connection = mysql.connector.connect(host='localhost', database='test', user='root', password='root') print("connection is open") query = """INSERT INTO Person (`Name`, `Age`, `DOB`, `Address`) VALUES ('ABC', 134,'2001-08-14', 'Rajasthan, India') """ cursor = co

Easiest way to Dockerize your Java application using Jib plugin

Containerizing a Java application is no easy an easy job, it requires to create Docker file with many commands within it along with base image and many other things. Due to all these things developers at Google has decided to simplify this process of Containerizing an application using some pluggins, so they have created a library called Jib . How to use Jib to dockerize/Containerize your Java/Springboot application: There is a Maven and Gradle plugin available which requires minimal configuration. For running Gradle execute : gradle jib  or gradle jibDockerBuild and Maven command: mvn compile jib:build mvn compile jib:dockerBuild In my opinion it is quite simple job to use this pluggin which simplifies the Java development and creates container images on the fly.

Kubernetes - 413 Request Entity Too Large

While configuring the NGINX Ingress Controller, you may face some issues with file upload requests. Using annotations you can customize various configuration settings.  In the case of nginx upload limits, use the annotation below: nginx.ingress.kubernetes.io/proxy-body-size: "0" This annotation removes any restriction on upload size. Of course, you can set this to a size appropriate to your situation, 0 means unlimited. I will update this blogpost when I get some free time, till then happy reading!