Posts

How to Use Redis Using Python

import redis # connect Server POOL = redis.ConnectionPool(host='', decode_responses=True, port='', password='') redis_connection = redis.StrictRedis(connection_pool=self.POOL) self.redis = redis_connection.method() Method - get, set, hset, getset, getrange, hgetall, hget, lrange, hmset, hmget, hdel, lrem, zrange, zincrby, zadd, lpush, pipeline (get multi key values), keys ( get only keys on variable_name) variable_name - hash Name key - key_name value - either strig or dict To Set Dict to Key within Hash Name POST: self.redis.hset(config.LIKE_USERS_DATA_REDIS_NAME, key_str, json.dumps(val_dict)) GET : self.redis.hgetall(config.CONTEST_PROCESS_DATA_NAME) POST : self.redis.hdel(config.CONTEST_PROCESS_DATA_NAME, key) To Set Value(str) within Hash Name ( its show like arrery) POST: value = str(self.app_id) + ':' + str(self.guid) + ':' + str(self.user_id) + ':' + is_liked status = self.redis.lpush(config.LIKE_QUEUE_REDIS_NAME, value) GET: list...

API Requested Raw Data In Different Ways Using python

TO GET Json Data using Form:      if 'json' in request.form:         json_of_metadata = request.form.to_dict(flat=False)         try:             meta_data_from_json = json_of_metadata['json']             meta_data_from_json_0 = meta_data_from_json[0]             str_meta_data_from_json_0 = str(meta_data_from_json_0)             meta_data_dict = json.loads(str_meta_data_from_json_0)             app.logger.info('JSON Extracted')         except Exception as e:     print(e) tO GET Json Data using Body:         if request.data is not None:             try:                 my_json = request.data.decode('utf8').replace("'", '"')             ...

How to Create Python Processor / Automated Task

Step-1: Create on python File ( module) Step-2:  This is Formate we need to used, add your logic ( .....ur logic) and If u want change sleep time to run or Automated Task every seconds/day/hours  import threading import time class ClassProcesses(threading.Thread):     def __init__(self, **kwargs):         threading.Thread.__init__(self) print('thread ID ----- ', threading.current_thread().ident) self.start()     def run(self):         print("RUN Method Started") while True: .....ur logic time.sleep(86400) # For 1 day         print("sleep time completed") if '__main__' == __name__:     ClassProcesses() Using this Schedule library u can easily run your code atomated import schedule class Test_1(): def run(): # schedule.every(2).minutes.do(self.contest_processor) schedule.every().day.at("00:00").do(excute_method) while True:       schedule.run_pending()   ...

How To Send SMS Using AWS SNS

import boto3 client = boto3.client(             "sns",             aws_access_key_id='',             aws_secret_access_key='',             region_name= ''         ) mobile_number = "+91 9999988888" Note: it will acept this following mobile number formates #+91 9999988888, +91-9999988888, +919999988888,+91-99999-88888, +9199999-88888, +9199999-88888, +91 9999988888              res = self.client.publish(PhoneNumber=mobile_no, Message=message) mess_id = res['MessageId'] res_status = res['ResponseMetadata'] status = res_status['HTTPStatusCode'] Note: To get aws access key & aws_secret_access_key, please follow this Article  - https://medium.com/codephilics/how-to-send-a-sms-using-amazon-simple-notification-service-sns-46208d82abcc

Mongodb Queries

First Connet with Your Database:  from pymongo import MongoClient mongo_client = MongoClient(host='', port='', username='',password='') db = mongo_client[str(self.database_name)] how to Search value on the Database: filter query in MongoDB - {email: {"$regex": 'kings', "$options": 'i'}} or using Python modify_str = '^' + partner_name + '$' filter_res = db .get_collection(collection_name).find_one( { 'name' : { "$regex" : modify_str, "$options" : 'i' } } ) if It retun None then No name match else get match documents How to Update Many Documents at Once res = db .get_collection(collection_name).update_many( {}, { "$set" : { "You_want_to_updated_key" : "value" } }, # don't insert if no document found upsert =False , array_filters =None ) $set is used to add a new key to ...

How To Install & setup Python 3.8 Version on Windows 10

Image
  1- Installing Python from Python.org Go on Python.org at the section where you can download the windows executables: https://www.python.org/downloads/windows/ Go down in the page and download the following executable (if your computer is 64 bits): Windows x86-64 executable installer Double click on the executable and install it 2- Add Python 3 to the windows 10 environment variable path I will suppose that you didn’t check the “add python to the path” checkbox when you installed it. Let’s see now how to add this new python 3 version to the path By default, it installs in the path: C:\Users\cypri\AppData\Local\Programs\Python ( cypri  will be replaced by your windows user name of course…) This is not convenient, because AppData is a hidden folder and it may cause problems with some python modules such as jupyter if you leave it here The move is to C:/ Change the name of the executable to python3.exe for convenience Let’s now edit the environment variables to add this new pyth...