I was trying to use couchbase in one of my android applications. This app will have static data that are scraped from the web. So I want to generate a cblite2 file with my python script and insert those data and then use this cblite2 file in android. I can load data from an existing file according to this. But how can I generate my initial cblite2 file?
Asked
Active
Viewed 201 times
2
DisappointedByUnaccountableMod
- 6,656
- 4
- 18
- 22
Shahrear Bin Amin
- 1,075
- 13
- 31
-
I guess you mean ‘scraped’ - extracted from HTML web pages - rather than ‘scrapped - thrown away, discarded – DisappointedByUnaccountableMod Feb 27 '21 at 09:07
1 Answers
1
You could use the cblite command line tool to create the database. There are a couple of ways to do the import. I'll describe what seems to me like the simplest way.
Have your script save the JSON documents to a directory. For this example, let's call the diretory json-documents. Use the desired document ID as the base name, and .json as the extension. For example, if you want a document's ID to be "foo", the filename would be foo.json.
Then use the cblite cp command to import the documents into a new database:
cblite cp json-documents/ myNewDatabase.cblite2
You can use the other cblite subcommands to verify the import was successful.
List the document IDs:
cblite ls myNewDatabase.cblite2
Display the contents of a document:
cblite cat myNewDatabase.cblite2 someDocumentId
dnault
- 8,340
- 1
- 34
- 53
-
To invoke `cblite` from Python, see https://stackoverflow.com/questions/89228/how-to-execute-a-program-or-call-a-system-command-from-python – dnault Feb 27 '21 at 20:04