replace content of json files - json

so I have 2 json file
The first json file looks like this
`{
"text": "Through your use of the site, you may have the opportunities to engage in commercial transactions with other users and vendors. You acknowledge that all transactions relating to any merchandise or services offered by any party, including, but not limited to the purchase terms, payment terms, warranties, guarantees, maintenance and delivery terms relating to such transactions, are agreed to solely between the seller or purchaser of such merchandize and services and you. WE MAKE NO WARRANTY REGARDING ANY TRANSACTIONS EXECUTED THROUGH, OR IN CONNECTION WITH THIS SITE, AND YOU UNDERSTAND AND AGREE THAT SUCH TRANSACTIONS ARE CONDUCTED ENTIRELY AT YOUR OWN RISK. ANY WARRANTY THAT IS PROVIDED IN CONNECTION WITH ANY PRODUCTS, SERVICES, MATERIALS, OR INFORMATION AVAILABLE ON OR THROUGH THIS SITE FROM A THIRD PARTY IS PROVIDED SOLELY BY SUCH THIRD PARTY, AND NOT BY US OR ANY OTHER OF OUR AFFILIATES.",
"section": [
"Disclaimer of Warranties"
]
},
{
"text": "Content available through this site often represents the opinions and judgments of an information provider, site user, or other person or entity not connected with us. We do not endorse, nor are we responsible for the accuracy or reliability of, any opinion, advice, or statement made by anyone other than an authorized britnex spokesperson speaking in his/her official capacity. Please refer to the specific editorial policies posted on various sections of this site for further information, which policies are incorporated by reference into these Terms of Use.",
"section": [
"Disclaimer of Warranties"
]
}`
and the other json file looks like this:
{
"text": "vigueur étendula création d'un organisme spécifique au sein de l'OPCO et d'une association paritaire nationale pour la mise en œuvre des garanties sociales des salariés, dénommée APNI, de construire un socle de droits collectifs en vue :",
"section": "[]"
},
{
"text": "– d'assurer l'effectivité par la mutualisation des droits sociaux attachés aux salariés par leur mise en œuvre ;",
"section": "[]"
},
I want to replace the content of "text" in first json file with content of second json file.
Please any help to do that with python.
Thanks

If you have it in json file you could do this:
import json
with open("name_file.json", 'r') as o:
raw_json = o.read()
python_list = json.loads(a)
and then you have list which you can modify easily

Related

Facebook Filtering New Page Experience

As some of you may know Facebook is migrating its users pages progressively to what is called the "New Page Experience" (NPE), the thing is some previous endpoints and data such as "locations" are not available by the same means anymore, for NPE you need to use the page token.
In my case, I used to do the following query on the facebook-graph-api with a facebook user token:
me/accounts?fields=access_token,category,tasks,name,is_published,locations.limit(100){access_token,category,name,is_published,parent_page}
This returned a JSON array with all the pages linked to the account of the user token, and the associated locations for each page.
However since the New Page Experience partial migration, if at least one page has been migrated to New Experience by Facebook, the whole call returns an error
{
"error": {
"message": "Invalid OAuth 2.0 Access Token",
"type": "OAuthException",
"code": 190,
"error_subcode": 2069032,
"is_transient": false,
"error_user_title": "Token d’accès utilisateur non pris en charge",
"error_user_msg": "Un token d’accès de Page est requis pour cet appel dans la nouvelle version des Pages."
}
Facebook has added a boolean field on pages called has_transitioned_to_new_page_experience, which should allow us to filter the pages.
However it doesn't seem to work, I've tried thing such as (true, 1, "true"...) which do work for other boolean parameters but not for has_transitioned_to_new_page_experience :
me/accounts?has_transitioned_to_new_page_experience=true // return all pages without filtering
me/accounts?is_place=true // Filters properly based on if the page is a place
I'd like to be able to single out the NPE, or do a filtered query to avoid needless calls through loops and array management, as most of the pages are still not NPE yet, and this would allow me to keep my code for "legacy pages" untouched.
Have any of you experienced this issue, or been able to solve it?
Maybe talk with the Facebook dev support?
Do you think this behavior is buggy?
Thanks!

How to show Google FAQ structured data when there are quick navigation href=#XXX and id=XXX

I'm using valid FAQ structured data for some of my pages and it works fine on all pages which don't have quick navigation menu (page jumps with href=#XXX and id=XXX). For those with quick navigation the search result shows the quick navigation menu instead.
How should I make the FAQ SD with higher priority?
The homepage has structured data with multi top-level types Question. Each of these types is embedded in the property mainEntity. This way your data has multi properties mainEntity.
Check the value of this property from the documentation of Schema:
Indicates the primary entity described in some page or other
CreativeWork.
In my humble opinion, the phrase "primary entity" means that this property should be the only one in the data of the web page. This my opinion is confirmed by the following example from the Google guide for the type FAQ (link of the example):
{
"#context": "https://schema.org",
"#type": "FAQPage",
"mainEntity": [{
"#type": "Question",
"name": "What is the return policy?",
"acceptedAnswer": {
"#type": "Answer",
"text": "Most unopened items in new condition and returned within <strong>90 days</strong> will receive a refund or exchange. Some items have a modified return policy noted on the receipt or packing slip. Items that are opened or damaged or do not have a receipt may be denied a refund or exchange. Items purchased online or in-store may be returned to any store.<br /><p>Online purchases may be returned via a major parcel carrier. <a href='http://example.com/returns'> Click here </a> to initiate a return.</p>"
}
}, {
"#type": "Question",
"name": "How long does it take to process a refund?",
"acceptedAnswer": {
"#type": "Answer",
"text": "We will reimburse you for returned items in the same way you paid for them. For example, any amounts deducted from a gift card will be credited back to a gift card. For returns by mail, once we receive your return, we will process it within 4–5 business days. It may take up to 7 days after we process the return to reflect in your account, depending on your financial institution's processing time."
}
}, {
"#type": "Question",
"name": "What is the policy for late/non-delivery of items ordered online?",
"acceptedAnswer": {
"#type": "Answer",
"text": "Our local teams work diligently to make sure that your order arrives on time, within our normal delivery hours of 9AM to 8PM in the recipient's time zone. During busy holiday periods like Christmas, Valentine's and Mother's Day, we may extend our delivery hours before 9AM and after 8PM to ensure that all gifts are delivered on time. If for any reason your gift does not arrive on time, our dedicated Customer Service agents will do everything they can to help successfully resolve your issue. <br/> <p><a href='https://example.com/orders/'>Click here</a> to complete the form with your order-related question(s).</p>"
}
}, {
"#type": "Question",
"name": "When will my credit card be charged?",
"acceptedAnswer": {
"#type": "Answer",
"text": "We'll attempt to securely charge your credit card at the point of purchase online. If there's a problem, you'll be notified on the spot and prompted to use another card. Once we receive verification of sufficient funds, your payment will be completed and transferred securely to us. Your account will be charged in 24 to 48 hours."
}
}
]
}
In this example, you can see that all questions are embedded in only one property mainEntity.
This example is in JSON-LD format which you can convert to microdata (as it is in your data) using this free tool online RDF Translator.
However, I dare say that the microdata format has a rather strong dependence on the source code in which this data is installed. The homepage of your website has invalid HTML and critical errors such as Duplicate ID. Check the following information from W3:
Syntax errors: Certain invalid syntax constructs, when parsed, result
in DOM trees that are highly unintuitive. Sometimes it is really hard
to pick up the structured data when the HTML is broken completely.
This invalid HTMLL may interfere with web page rendering.

DataProcessingFailed in Microsoft Custom Translator? Is there any log file?

I am using microsoft custom translator hub for translation.
Currently I am trying to train only one work for which I have created training file with 10,000 sentences for english and spanish. In training also I am using the same parallel files.
For some documents its working fine but for some it throws "DataProcessingFailed" error.
Is there any log file where I can see the error cause?
My Training file is as follows:
The party has signed below
The party has signed below
The party has signed below
The party has signed below
The party has signed below
The party has signed below
The party has signed below
The party has signed below
10,000 times this line
Spanish file
La parte ha firmado a continuación
La parte ha firmado a continuación
La parte ha firmado a continuación
La parte ha firmado a continuación
La parte ha firmado a continuación
La parte ha firmado a continuación
La parte ha firmado a continuación
10,000 times this line
Thanks
You'll need to submit 10000 different sentences to train a custom model using Custom Translator. Or you can use a dictionary if you want Microsoft Translator to translate an instance in a source phrase or sentence using the translation you provided in the dictionary.

Different results with Microsoft Translator API / Web Translator

I am running test to select an MT API, and while testing the Microsoft Translator have found that I get different results for the same sentence using the API from a script than what I get when passing the whole URL to the Web Translator.
For this sentence in EN source:
AppFlow is supported on NetScaler appliances running version 9.3 and above with nCore build.
(first FAQ in https://docs.citrix.com/en-us/netscaler/12-1/networking-faq/appflow-faq.html)
I get this result for FR, when passing that single sentence for translation in the https://www.bing.com/translator page and via a Python script calling the API:
AppFlow est pris en charge sur les appliances NetScaler qui exécutent la version 9,3 et plus avec ncore Build.
However, the same sentence in the whole translated URL in Web Translator reads:
AppFlow est pris en charge sur les appliances NetScaler exécutant la version 9.3 et ci-dessus avec nCore construire.
(https://www.microsofttranslator.com/bv.aspx?from=en&to=fr&a=https%3A%2F%2Fdocs.citrix.com%2Fen-us%2Fnetscaler%2F12-1%2Fnetworking-faq%2Fappflow-faq.html)
My understanding is that the API now works with NMT by default. I would like to understand why Web Translator presents a different result. I was going to do some assessment by passing URLs into Web Translator, but if this is not using the API with NMT, then I cannot use this method.
Thank you.
Version 3 of the Translator API defaults to NMT. http://bing.com/translator also defaults to NMT.
The full web page translation in bing.com and the Edge browser extension still use SMT for most language pairs, including English<>French. This is for scalability reasons.

Create REST API without using any backend

How do you create a rest api without using any backend technologies such as node, express? ie: Is it possible to create an api using only client side framework such as react, vue and no server side involved?
I would like to create a very simple rest api which I can host either on github pages or gitlab pages.
I would like a live rest api that I can access via my own domain such as http://username.github.io and not a fake one that you can create using json-server or My JSON Server - and would be able to do the following.
Here is the description of what the api should do.
/quotes.txt - Read the contents of the quotes.txt file and display it
/quotes.json - Read the contents of the quotes.txt file and convert it
to json format
/random.txt - Read the contents of the quotes.txt file and display a
random quote in txt format
/random.json - Read the contents of the quotes.txt file and display a
random quote in json format
Output of the API
/quotes.txt
To be or not to be that is the question - Author Unknown
All your dreams can come true if you have the courage to pursue them - Walt Disney
Stand up for what you believe in even if you are standing alone -
/quotes.json
[
{
"quote": "To be or not to be that is the question",
"author": "Author Unknown"
},
{
"quote": "All your dreams can come true if you have the courage to pursue them",
"author": "Walt Disney"
},
{
"quote": "Stand up for what you believe in even if you are standing alone",
"author": ""
}
]
/random.txt
All your dreams can come true if you have the courage to pursue them - Walt Disney
/random.json
{
"quote": "All your dreams can come true if you have the courage to pursue them",
"author": "Walt Disney"
}
You could use json-server to serve a JSON file. It supports "canonic" ways to express RESTful requests. This tool can be used on a dev machine or on a intranet server. Here's a blog post about how to set it up.
My JSON Server is a service that does the same exact thing in the Internet environment for you. There are also competing services with similar functionalities, e.g. myjson.com. I'm sure you will find more if you search online.
P.S. I'm sure you'll need to do some massaging to actually translate .txt -> .json. I've never seen services that work against .txt files rather than .json ones.
Ugh. I really like question edits that invalidate the answers.