About the examples
On this page
Each example is a complete program that does one job from start to finish, such as writing a search's results to a CSV file. Its page is the program itself, read top to bottom with the explanation around the code, and the program is there to download at the top of the page. Every release of the examples runs each of them against the API, so a program you download works with the API these pages describe.
Running one
Download the program into a folder of its own, with any file its page offers beside it. The page's What you need says which language version and packages it needs, and how to run it.
The values you would change, such as the search, the month or the name of the file it writes, are near the top of the program rather than options on the command line: open the file and edit them.
Each example asks you to log in when it starts. It prints a link, you open it and log in with
your reconnectchina.org account, and the login ends with the program. A program that has to run
without you keeps a token in a file instead: Creating a token for a script.
Until we have reviewed your registration and your account is in an organization, a program
stops with the problem type no-organization.
How they fit together
Saved searches from a keyword workbook reads a spreadsheet of keywords by sector and saves one search per sector. The others run searches like these by name, so the keywords stay in the spreadsheet:
- Search results as a CSV file runs one search into a CSV file.
- A workbook of documents and counts by sector runs every sector's search for one month in China into an Excel workbook: the documents, and how many there are by level and province.
- Monthly counts by sector, with a chart counts every sector's documents per month in China over most of a year, beside all documents, and charts them. It chooses its months with date math, so it covers the latest ones whenever it runs.
The CSV example also runs a search written into the program, so it is the one to start with if you have one search in mind. If you keep your keywords in a spreadsheet, start with the keyword workbook.
What they call is described on its own page: Search and Next page of a search, Save a search, Read a saved search and Run a saved search, and Full detail for up to 32 documents. Each saves its searches in one scope, set near its top: Saved searches and scopes says which there are. The date math is Instant expressions, and how a month in China is named and counted is Dates and time zones.
Python
This program runs one search, pages through every result and writes one row per document to a CSV file: its dates, what kind of document it is, who issued it, its title in English and Chinese, a short English summary and the link back to ReConnect China. From there you count, plot, write a report or train a model, in whatever tool you like.
Saved searches from a keyword workbook
This program reads a workbook that lists keywords by sector and saves one search per sector under a name, finding any of that sector's keywords. You keep the keywords where you already keep them, in a spreadsheet, and whenever the sheet changes you run the program again.
A workbook of documents and counts by sector
This program runs each sector's saved search for one month and writes a new Excel workbook. Its first sheet lists every document a sector's search found, one row per document and sector, with the title in English and Chinese, a summary, the document number, the issuing department, the date, the length of the text and the links to the source and to ReConnect China. Its second sheet counts the documents by sector, administrative level and province.
Monthly counts by sector, with a chart
This program counts each sector's policy documents per month over the last eleven whole months, and all policy documents over the same months, and writes a new Excel workbook with the counts, each sector's share per 1,000 policy documents, and a line chart of each. It answers whether a subject is rising, and whether it rises faster than policy as a whole.