How to move mutiple categories using Pywikibot and category.py? - mediawiki

I know a single category can be moved by using like this:
python pwb.py category move -from:Apple -to:Banana
But, I can't find the way to move mass categories in just one command.
Is there any options like -pairsfile in movepages.py? It would be great if a file containing the names of the categories was available.

Related

while searching in elasticsearch,if we search for a word "brother" which is present more than once in array of json

then if we write a nested query to get brother then will we get the both occurences present in the array or json or only single occurence?
for example
if we are querying to get the word "brother" and its present more than twice in the array of json
will it show only one occurence of brother or multiple occurences?
hence we are handling multiple files we need the file id in which the word is present and if single word is present in a file more than once is it possible to get the word in that single file more than once?
i tried to get the single file id more than once because the single file contained the word more than once in multiple jsons but im getting the file id only once ...
If you are using kibana sql, you will search any occurence in each elasticsearch doc. If you search by "brother" you will get 1 occurence from each doc contains the word "brother". If you have 3 docs and once has 3 times the word you are searching for and the other 2 have the word once each, you will get 3 hits.
We have to use a for loop in any programming language and we will get only max 3 hits in inner hits. We have to access the json file and load it in Python for example and then use for loop and we can have upto 3 hits.by this process we can access upto 3 inner hits in a same file.
the code:-
we can fetch em in this way
for i in range(some_value):
try:
uniq_id = data["hits"]["hits"][i]["_id"]
start = data["hits"]["hits"][i]["inner_hits"]["key"]["hits"]["hits"][0]["fields"]["key.start"][0]
check = data["hits"]["hits"][i]["inner_hits"]["key"]["hits"]["total"]["value"]

importing CSV into FileMaker Pro 18 with CSV header line

Despite searching both Google and the documentation I can't figure this out:
I have a CSV file that has a header line, like this:
ID,Name,Street,City
1,John Doe,Main Street,Some City
2,Jane Done,Sideroad,Other City
Importing into FileMaker works well, except for two things:
It imports the header line as a data set, so I get one row that has an ID of "ID", a Name of "Name", etc.
It assigns the items to fields by order, including the default primary key, created date, etc. I have to manually re-assign them, which works but seems like work that could be avoided.
I would like it to understand that the header line is not a data set and that it could use the field names from the header line and match them to the field names in my FileMaker table.
How do I do that? Where is it explained?
When you import records, you have the option to select a record in the source file that contains field names (usually the first row). See #4 here.
Once you have done that, you will get the option to map the fields automatically by matching names.
If you're doing this periodically, it's best to script the action. A script will remember your choices, so you only need to do this once.

Best way to parse a big and intricated Json file with OpenRefine (or R)

I know how to parse json cells in Open refine, but this one is too tricky for me.
I've used an API to extract the calendar of 4730 AirBNB's rooms, identified by their IDs.
Here is an example of one Json file : https://fr.airbnb.com/api/v2/calendar_months?key=d306zoyjsyarp7ifhu67rjxn52tv0t20&currency=EUR&locale=fr&listing_id=4212133&month=11&year=2016&count=12&_format=with_conditions
For each ID and each day of the year from now until november 2017, i would like to extract the availability of this rooms (true or false) and its price at this day.
I can't figure out how to parse out these informations. I guess that it implies a series of nested forEach, but i can't find the right way to do this with Open Refine.
I've tried, of course,
forEach(value.parseJson().calendar_months, e, e.days)
The result is an array of arrays of dictionnaries that disrupts me.
Any help would be appreciate. If the operation is too difficult in Open Refine, a solution with R (or Python) would also be fine for me.
Rather than just creating your Project as text, and working with GREL to parse out...
The best way is just select the JSON record part that you want to work with using our visual importer wizard for JSON files and XML files (you can even use a URL pointing to a JSON file as in your example). (A video tutorial shows how here: https://www.youtube.com/watch?v=vUxdB-nl0Bw )
Select the JSON part that contains your records that you want to parse and work with (this can be any repeating part, just select one of them and OpenRefine will extract all the rest)
Limit the amount of data rows that you want to load in during creation, or leave default of all rows.
Click Create Project and now your in Rows mode. However if you think that Records mode might be better suited for context, just import the project again as JSON and then select the next outside area of the content, perhaps a larger array that contains a key field, etc. In the example, the key field would probably be the Date, and why I highlight the whole record for a given date. This way OpenRefine will have Keys for each record and Records mode lets you work with them better than Row mode.
Feel free to take this example and make it better and even more helpful for all , add it to our Wiki section on How to Use
I think you are on the right track. The output of:
forEach(value.parseJson().calendar_months, e, e.days)
is hard to read because OpenRefine and JSON both use square brackets to indicate arrays. What you are getting from this expression is an OR array containing twelve items (one for each month of the year). The items in the OR array are JSON - each one an array of days in the month.
To keep the steps manageable I'd suggest tackling it like this:
First use
forEach(value.parseJson().calendar_months,m,m.days).join("|")
You have to use 'join' because OR can't store OR arrays directly in a cell - it has to be a string.
Then use "Edit Cells->Split multi-valued cells" - this will get you 12 rows per ID, each containing a JSON expression. Now for each ID you have 12 rows in OR
Then use:
forEach(value.parseJson(),d,d).join("|")
This splits the JSON down into the individual days
Then use "Edit Cells->Split multi-valued cells" again to split the details for each day into its own cell.
Using the JSON from example URL above - this gives me 441 rows for the single ID - each contains the JSON describing the availability & price for a single day. At this point you can use the 'fill down' function on the ID column to fill in the ID for each of the rows.
You've now got some pretty easy JSON in each cell - so you can extract availability using
value.parseJson().available
etc.

Best way to use a custom table in a relationship (in ExpressionEngine)?

So, I’m a bit on how to use a separate table in a relationship, or something like that…
I have a table with around 5000 hotels called exp_h_hotels.
On my website, I use the pages module to create a static subpage for each part of the country. I want to list all hotels that belong to a specific region.
I have understood that I can’t do something like this (using ExpressionEngine tags with the query module):
{exp:query sql="SELECT * FROM exp_h_hotels WHERE h_regionname ='{regionname}'"}
{hotel_name}
{/exp:query}
Anyone knows the best way to go forward with this?
I have looked into using the ExpressionEngine API to insert the data into a channel – however, I get the feeling that it wouldn’t be optimal to flood the channel entries table with 5000 posts with 14-20 fields with data each.
There's no reason why this shouldn't work as you expect, so long as your exp:query tag is inside your channel:entries tag:
{exp:channel:entries channel="pages" limit="1"}
<h1>Hotels in {regionname}</h1>
<ul>
{exp:query sql="SELECT * FROM exp_h_hotels WHERE h_regionname ='{regionname}'"}
<li>{hotel_name}</li>
{/exp:query}
</ul>
{/exp:channel:entries}
However, for the long-term, importing your hotels into a new channel in EE is a much better plan. You could export from your database to CSV (using phpMyAdmin perhaps) and then import into EE using DataGrab. Nothing wrong with adding 5000 new entries to EE.

bot to edit mediawiki categories

I have a mediawiki with different type of categories.
If a page has 2 categories
[[Category:Pear]][[Category:Strawberry]])
I want to add a third category
[[Category:Fruit_Salad]]
Is it possible to do that automatically? (using a bot for instance)
Edit: In fact, what I need is an API for categories
a way to read the category
a way to add a new category
The rest can be done by any program
You are probably looking for the pywikipediabot framework. (Check catlib.py for the category manipulation code, and category.py for an end-user-friendly mass category modification bot.)