Skip to main content

Posts

Showing posts from March 11, 2018

How to find or get urls in a string

Regex to find urls in string import re url = '<p>Hello World</p><a href="ttp://example.com">More Examples</a><a href="https://example2.com">Even More Examples</a>' urls = re . findall( 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' , url) print urls

Parsing a YAML file

YAML is a configuration file format The file itself might look like this: mysql: host: localhost user: root passwd: my secret password db: write-math other: preprocessing_queue: - preprocessing.scale_and_center - preprocessing.dot_reduction - preprocessing.connect_lines use_anonymous: yes You can read it like this: #!/usr/bin/env python import yaml #Import yaml module with open ( "example.yml" , 'r' ) as stream: #open the yaml file in read mode try : myDict = (yaml . load(stream)) #load the file into a dictionary called 'Dict' for section in myDict: print section print myDict[ 'mysql' ] except yaml . YAMLError as exc: print (exc) That's all you need. Now the entire yaml file is in 'MyDict' dictionary. Output: other mysql {'passwd': 'my secret password' , 'host': 'localhost...

GMT to desired date and time format

Converting GMT to desired date and time format First, you need to convert the string to a datetime object using strptime dt = datetime.datetime.strptime('Wed, 14 Mar 2018 07:30:00 GMT','%a, %d %b %Y %H:%M:%S %Z') Then convert back in the desired string format using strftime dt.strftime('%Y/%m/%d') Complete code: import datetime dt = datetime . datetime . strptime( 'Wed, 14 Mar 2018 07:30:00 GMT' , '%a, %d %b %Y %H:%M:%S %Z' ) print dt . strftime( '%Y/%m/ %d ' ) Output : '2018/03/14'

Sending Emails using Mandrill API in python

Mandrill is a great API for sending transactional e-mails. Transactional e-mails are emails such as order confirmations, user signups, forgotten passwords and anything that the user may receive during normal use. Mandrill  is  a simple REST API. By creating an account at Mandrill.com, you can get your API keys, and then you are ready to make calls to Mandrill. Requirements : Python 2.6+, Python 3.0+ Getting the library : The preferred method of installing the Mandrill Python API client is by using pip. $ sudo pip install mandrill Using the library: Now that you have a copy of the library in your project, you're ready to start using it. All uses of the Mandrill API start by importing the library module and instantiating the Mandrill class. import mandrill mandrill_client = mandrill . Mandrill( 'YOUR_API_KEY' ) They are different  api call categories.In that we are using messages calls Messages calls: Send a new transactional message through Mandrill: import m...

Basic Linux commands

Linux has a basic impact in our life. However, getting started with Linux just make you discomfort for the first time. Because on Linux, you usually should use terminal commands instead of just clicking the launcher icon (as you did on Windows).But don't worry with experience of more than 3 years as a Developer i feel  Linux is best as using it.We will give you the mostly used linux commands. So let's get started with the list of 10 Linux Basic commands - 1. sudo ("superuser do") - Allows you to run other commands with administrative privileges. This is useful when, for example, you need to modify files in a directory that your user wouldn't normally have access to. $ sudo su 2.   ls ("list") - Lists all files and folders in your current working directory. You can also specify paths to other directories if you want to view their contents. /home$ ls 3. cd ("change directory") - Changes the directory you are currently working in. You can use ...