Posts

Create cronjob for django management command async process

 Recently i have facing some problem with cronjob set with django project  In my case i need to pull the data from external api and save the data in every minute then i write this code Please do following steps. 1. Create management folder in your app folder and in management folder add commands folder. add file e.g import_jobs.py from __future__ import unicode_literals, absolute_import, division from django.core.management.base import BaseCommand import logging logger = logging.getLogger(__name__) #------------------------------------------------------------------------------- # Command #------------------------------------------------------------------------------- class Command(BaseCommand): help = "Add Jobs from BH Portal" #--------------------------------------------------------------------------- # handle #--------------------------------------------------------------------------- def handle( self , *args, **options): # add your log

One Drive python connection

redirect_uri = 'http://localhost:8000/' client_secret = 'your app password' client_id='app id' api_base_url='https://api.onedrive.com/v1.0/' scopes=['wl.signin', 'wl.offline_access', 'onedrive.readwrite']    client = onedrivesdk.get_default_client(     client_id=client_id, scopes=scopes) auth_url = client.auth_provider.get_auth_url(redirect_uri) #this will block until we have the code code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri) client.auth_provider.authenticate(code, redirect_uri, client_secret) print(client) f = onedrivesdk.Folder() i = onedrivesdk.Item() i.name = 'python' i.folder = f

Google Calendar api with django application

I have used google calendar api with django application. I have create some appointments on google calendar using django. There are  following steps to integrate with django application. 1. Firstly goes to this link google developer console      and then create a project and then create application 2.  save the client secret key and client id. 3.  Then go to your django application where you used calendar api 4. now install the library using command  <pip install google-api-python-client>then go to next step 5. I have used in my views.py example:-          from googleapiclient import discovery from oauth2client import tools from oauth2client.client import OAuth2WebServerFlow from oauth2client.file import Storage import httplib #--------------------------------------------------------------------------- # google_calendar_connection #--------------------------------------------------------------------------- def google_calendar_connect

Google recaptcha integration with django applicaton

Recently I have used google recaptcha with my django application for registration process. There are following steps to integrate with your django application.  Firstly go to this link -  https://developers.google.com/recaptcha/   and click on get started. Now click on  add  sign up api keys for google recaptcha. enter label name (e.g.- Myapp) and domain(e.g. - localhost) for your local project and saved the recaptcha copy the site key and secret key and added into your settings for example       RECAPTCHA_PUBLIC_KEY = '6LdUAAAAAD97sRFALHoKmVWbHxE7kdXAUCed' RECAPTCHA_PRIVATE_KEY = '6LUAAAAAARB_-RRMI4ynXAw8mDC8fVUrDud'  one thing more add RECAPTCHA_VERIFICATION_URL =  'https://www.google.com/recaptcha/api/siteverify'   in settings.py file which are used in your forms. Then go to your template where you show recaptcha . and add this code in your template. <div class="g-recaptcha" data-sitekey="6Ld_EwkUAAAAADmVWbHxE7kdXAUCed"

retrive google contacts using google contactapi with django

Firstly we create  a project in google developer Console using following links: https://console.developers.google.com/home/dashboard?project=brickit-1134&pli=1 After create project click on side panel in google developer console and select "API MANAGER" and select google contact api and enable the api .After enable the api click on side pannel on "credentials" and click on add credentials. There are three options: 1. API key 2. OAuth 2.0 Client id 3. service account click on second options and go to consent screen and fill up the product name and save it after save click on web application and fill up the name and authorized redirect urls which is necessary "authorized redirect ur"l ==> your django application url where we redirect. After save it that generate a "client id" and "client secret" please save it. Now goes to your django application. install gdata in your virtualenv and paste code in your views: