Python CouchDB and pythoncouchdb
Install the python couchDb Library:
Https://pypi.python.org/pypi/CouchDB/0.10
Connect to the server
>>> import couchdb>>> couch = couchdb.Server('http://example.com:5984/')
Create a database
>>> Db = couch. create ('test') # create a database> db = couch ['mydb'] # use an existing database
Create a document and insert it to the database:
>>> Doc = {'foo': 'bar'} >>> db. save (doc) ('taobao', '1-taobao') >>> doc {'_ rev': '1-4c6114c65e295552ab1019e2b046b10e ', 'foo': 'bar ', '_ id': 'e0658cab843b59e63c8779a9a5000b01'} the save () method returns the '_ id',' _ rev' Field
Query a database by id
>>> db['e0658cab843b59e63c8779a9a5000b01']<Document 'e0658cab843b59e63c8779a9a5000b01'@'1-4c6114c65e295552ab1019e2b046b10e' {'foo': 'bar'}>
Update document:
>>> data = db["5fecc0d7fe5acac6b46359b5eec4f3ff"] >>> data['billSeconds'] = 191>>> db.save(data)(u'5fecc0d7fe5acac6b46359b5eec4f3ff', u'3-6b8a6bb9f2428c510dcacdd5c918d632')
Traverse Database
>>> for id in db:... print id...'e0658cab843b59e63c8779a9a5000b01'
Delete documents and clear Databases
>>> db.delete(doc)>>> couch.delete('test')
Repeated errors occur when Python calls CouchDB insert.
You can use pydoc couchdb to query its documentation
How does python operate windows Services?
You can use the OS module to operate services in windows.
The command to query a service status is:
SC query [servicename]
For example, to query the WebClient Service Status:
C: \ Documents ents and Settings \ Administrator> SC query WebClient
SERVICE_NAME: WebClient
TYPE: 10 WIN32_OWN_PROCESS
STATE: 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE: 0 (0x0)
SERVICE_EXIT_CODE: 0 (0x0)
CHECKPOINT: 0x0
WAIT_HINT: 0x0
Therefore, the starting point of this python script can first query the status of a service. If the status is not RUNNING, start it. The key code is as follows:
Result = OS. popen ("SC query WebClient ")
If not "RUNNING" in result:
OS. system ("SC start WebClient ")
Let the script run on a regular basis, and hope to help you