Saturday 18 October 2014

What is MongoDB and how to install MongoDB?

"MongoDB is an open-source document database that provides high performance, high availability, and easy scalability. Documents (objects) map nicely to programming language data types. Embedded documents and arrays reduce need for joins."

Other words:

"A MongoDB deployment hosts a number of databases. database holds a set of collections. collection holds a set of documents.document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data."

Document Database

A record in MongoDB is a document, which is a data structure composed of field (Key) and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.A MongoDB document.

{
  "name":"Rossum",
  "age":54,
  "status":true,
  "groups":["news","sports"],
}

The advantages of using documents are:

  • Documents (i.e. objects) correspond to native data types in many programming languages.
  • Embedded documents and arrays reduce need for expensive joins.
  • Dynamic schema supports fluent polymorphism.
  • It is in document (Json) format, so there is no problem with join tables that’s why it’s speed is very fast rather then other database like Msql, Sqlserver and others.

Key Features

·         High Performance
·         High Availability
·         Automatic Scaling
·         Flexibility
·         Ease of use
·         Power

Installation of  MongoDB

First download mongoDB for different OS then go through below steps

Install on Windows

MongoDBDownload- 64-bit zip | msi
MongoDB Download- 32-bit zip | msi
MongoDB Download- 64-bit legacy zip | msi

Install on Linux

Install on Mac

Install on Solarisis


If you want previous release then click on below link

Steps:

  • Now download it and extract it in any directory for linux, mac, solorisis and install msi for windows.
  • Open terminal and go through same directory where mongoDB extract by cd command
  • Type this command  Python setup.py install

Now MongoDB is installed successfully . If you want to see mongodb UI interface then download below download and install the  it will show UI interface on your system for MongoDB.

Robomongo-this is for MongoDB UI interface. There are number of UI interface but according to me it’s good.


Monday 13 October 2014

How to change root password for mysql and phpmyadmin

It depends on your configuration. Follow the instruction below to reconfigure phpmyadmin, and reset MySQL password.

  1. Ctrl + Alt + T to launch terminal
  2. sudo dpkg-reconfigure phpmyadmin
  3. Connection method for MySQL database for phpmyadmin: unix socket
  4. Name of the database's administrative user: root
  5. Password of the database's administrative user: mysqlsamplepassword
  6. MySQL username for phpmyadmin: root
  7. MySQL database name for phpmyadmin: phpmyadmin
  8. Web server to reconfigure automatically: apache2
  9. ERROR 1045
  10. ignore
  11. sudo dpkg-reconfigure mysql-server-5.5
  12. New password for the MySQL "root" user: mysqlsamplepassword
  13. Repeat password for the MySQL "root" user: mysqlsamplepassword
  14. After all this run following command on terminal to secure your mysql server. sudo mysql_secure_installation
  15. Enter current password for root (enter for none): mysqlsamplepassword
  16. Change the root password? [Y/n] n
  17. Remove anonymous users? [Y/n] y
  18. Disallow root login remotely? [Y/n] y
  19. Remove test database and access to it? [Y/n] y
  20. Reload privilege tables now? [Y/n] y
Wish it helps!

Thanks

Thursday 2 October 2014

Read any system's drive data in network using python

By wmi module it's not possible to read all files of network system but we can read by two ways.

1) Mount remote system drive in to your local system.
2) set netuse virtual connection and access to read files.

For mounting remote system drive in your local system, use below code
import win32api
import win32net
import win32netcon,win32wnet

username='user'
password='psw'

try:
    win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, 'Z:','\\\\192.168.1.18\\D$', None, username,password, 0)
    print "connection established successfully"
except:
    print  "connection not established"

 

After connection you can read all files data
 

for root, dirnames, filenames in os.walk('\\\\192.168.1.18\D$'):
        for filename in filenames:
            match=os.path.join(root, filename)
            datafile = file(match)
            for line in datafile:
               print line


2) for set virtual connection use below code
 

import win32api
import win32net

ip = '192.168.1.18'
username = 'ram'
password = 'ram@123'

try:
    use_dict={}
    use_dict['remote']=unicode('\\\\192.168.1.18\C$')
    use_dict['password']=unicode(password)
    use_dict['username']=unicode(username)
    win32net.NetUseAdd(None, 2, use_dict)
except:
    print  "connection not established"


Hi Guys if these all post are helpful for you then please follow my blog through google plus or Facebook, I will share other useful post for you . If you have any feedback for me please share it.

Thanks guys for your support.

Python urllib2 post request

We can post a request through urllib with parameter. we can also encode a dict using urllib like this:

See below code :
import urllib
import urllib2

url = 'http://example.com/...'
values = { 'productslug': 'bar','qty': 'bar' }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
print result


You can encode value through urlencode and send it securely by requested url.  you can also send data without encryption. It will execute url request and return response.


Hi Guys if these all post are helpful for you then please follow my blog through google plus or facebook, I will share other useful post for you . If you have any suggestion for me please share to me.

Thanks guys for your support.

Wednesday 1 October 2014

Upload or send file to ftp server in python

you can send or upload any file to ftp server very easy using python. In below code i have used ftplib module for sending files.

use below code and run it.


import ftplib
def send_File(file, user, pwd):
    ftp = ftplib.FTP("ftp.example.com")
    ftp.login(user, pwd)
    ftp.storlines("STOR " + file, open(file))
send_File("users.txt","username","password")

Thank you guys for your support.

Using the urllib Module to Fetch a Remote Resource

If you want to read html content of any site or any js, css, other files also then use below code it will show all files content. Only you have to provide the url and some time if you want to read any js, css file which is present any root path then give "domain_name.com/path_of_any_file/", it will show that file content.

import urllib
import sys
f = urllib.urlopen("http://www.google.com")
while 1:
    buf = f.read(2048)
    if not len(buf):
        break
    sys.stdout.write(buf)


Thank you guys for your support.

How to read website html, css, js files using python

If you want to read html content of any site or any js, css, other files also then use below code it will show all files content. Only you have to provide the url and some time if you want to read any js, css file which is present any root path then give "domain_name.com/path_of_any_file/", it will show that file content.

import urllib
import sys
f = urllib.urlopen("http://www.google.com")
while 1:
    buf = f.read(2048)
    if not len(buf):
        break
    sys.stdout.write(buf)


Thank you guys for your support.

How to Read POP3 E-mail messages from accounts using python

Use below code for reading POP3 emails from any account.


import poplib
import getpass
serveur = poplib.POP3('mail.example.com')
#User Authentication
serveur.user(getpass.getuser())
serveur.pass_(getpass.getpass())
# Get message count
nbr_message = len(serveur.list()[1])
# print message subjects
for elem in range(nbr_message) :
    for msg in serveur.retr(elem+1)[1]:
        if msg.startswith('Subject'):
            print msg
            break
serveur.quit()

Thank you guys for your support.

How to Extract list of URLs in a web page using python

I think this post is very useful for finding the url for downloading and extracting url using python code.
Here I am using "sgmllib" python built in module for finding urls.

Use below code and run it with any urls


__author__ = "Ashish jain (example@gmail.com)"
__version__ = "$Revision: 1.0 $"
__date__ = "$Date: 2014/10/01 21:57:19 $"
__license__ = "Python"
from sgmllib import SGMLParser
class URLLister(SGMLParser):
  def reset(self):
    SGMLParser.reset(self)
    self.urls = []
  def start_a(self, attrs):
    href = [v for k, v in attrs if k=='href']
    if href:
      self.urls.extend(href)
if __name__ == "__main__":
  import urllib
  usock = urllib.urlopen("http://diveintopython.net/")
  parser = URLLister()
  parser.feed(usock.read())
  parser.close()
  usock.close()
  for url in parser.urls:
   print url

Thank you guys for your support.

How to read email message from .msg file

For reading the .msg file, I am using python built in library "email". you can read .msg file by below code.

import email
def read_MSG(file):
    email_File = open(file)
    messagedic = email.Message(email_File)
    content_type = messagedic["plain/text"]
    FROM = messagedic["From"]
    TO = messagedic.getaddr("To")
    sujet = messagedic["Subject"]
    email_File.close()
    return content_type, FROM, TO, sujet
myMSG= read_MSG("client.msg")
print myMSG

Thank you guys for your support.