Do business pages have user ID numbers? - html

I created a business page only and am the administrator. Everything that I have read telling me how to find my user id# leads me to the page number. Do business pages have user id#s? If so how do I find it? I need it for the fb:admins content. Please, I have been trying to figure this out for days and my head is physically spinning.

To find the PAGE id, just do the following. http://graph.facebook.com/YourPageNameHere. If you don't have a page name yet (less than X number of fans), then user the # in the link to your page instead of the page name.
example for Coca Cola corp: http://graph.facebook.com/CocaCola
{
"id": "40796308305",
"name": "Coca-Cola",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/276879_40796308305_1578420141_s.jpg",
"link": "https://www.facebook.com/coca-cola",
"likes": 36645415,
"category": "Food/beverages",
"website": "http://www.coca-cola.com",
"username": "coca-cola",
"founded": "1886",
"description": "On May 8, 2011, Coca-Cola marked its 125th anniversary. Created in 1886 in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage at Jacob's Pharmacy by mixing Coca-Cola syrup with carbonated water. \n\nCoca-Cola was patented in 1887, registered as a trademark in 1893 and by 1895 it was being sold in every state and territory in the United States. In 1899, The Coca-Cola Company began franchised bottling operations in the United States. \n\nCoca-Cola might owe its origins to the United States, but its popularity has made it truly universal. Today, you can find Coca-Cola in virtually every part of the world.",
"can_post": true,
"checkins": 77,
"talking_about_count": 215181
}
example for GoDaddy.com: http://graph.facebook.com/GoDaddy
{
"id": "8749090685",
"name": "GoDaddy.com",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/276455_8749090685_6602072_s.jpg",
"link": "https://www.facebook.com/GoDaddy",
"likes": 107451,
"category": "Internet/software",
"website": "http://GoDaddy.com/ http://twitter.com/GoDaddy http://youtube.com/GoDaddy http://www.linkedin.com/companies/godaddy.com ",
"username": "GoDaddy",
"company_overview": "Go Daddy helps people and businesses create and grow their online presence. Go Daddy is the world's dominant domain registrar, is also the top hosting provider in North America and the world's #1 provider of new SSL certificates. Go Daddy develops most all of its 52+ product offerings. Go Daddy has more than 7 million active customers worldwide and provides 24/7 industry-best customer service. The company is U.S. based and doesn't outsource or off-shore a single job.",
"products": "http://GoDaddy.com/Domains\nhttp://GoDaddy.com/Hosting\nhttp://GoDaddy.com/Email\nhttp://GoDaddy.com/SSL",
"can_post": true,
"talking_about_count": 2727
}
However, an fd:admin should be a USER id, not a PAGE id. You can use the graph API explorer to find out your USER id. Go to: https://developers.facebook.com/tools/explorer

Related

Clojure: parse json and extract values

I'm making an API call and using Cheshire to parse the JSON:
(defn fetch_headlines [source]
(let [articlesUrl (str "https://newsapi.org/v2/top-headlines?sources="
source
"&apiKey=a688e6494c444902b1fc9cb93c61d6987")]
(-> articlesUrl
client/get
generate-string
parse-string)))
The JSON payload:
{"status" 200, "headers" {"access-control-allow-headers" "x-api-key,
authorization", "content-type" "application/json; charset=utf-8",
"access-control-allow-origin" "*", "content-length" "7434",
"connection" "close", "pragma" "no-cache", "expires" "-1",
"access-control-allow-methods" "GET", "date" "Thu, 28 Mar 2019
20:22:16 GMT", "x-cached-result" "false", "cache-control" "no-cache"},
"body"
"{\"status\":\"ok\",\"totalResults\":10,\"articles\":[{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":null,\"title\":\"Trump:
Mueller probe was 'attempted takeover' of government - CNN
Video\",\"description\":\"In a Fox News interview with Sean Hannity,
President Trump called special counsel Robert Mueller's probe an
\\"attempted takeover of our
government.\\"\",\"url\":\"http://us.cnn.com/videos/politics/2019/03/28/trump-mueller-probe-attempted-takeover-hannity-cpt-sot-vpx.cnn\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190324191527-06-trump-mueller-reaction-0324-super-tease.jpg\",\"publishedAt\":\"2019-03-28T20:09:04.1891948Z\",\"content\":\"Chat
with us in Facebook Messenger. Find out what's happening in the world
as it
unfolds.\"},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":null,\"title\":\"James
Clapper reacts to call he should be investigated - CNN
Video\",\"description\":\"Former Director of National Intelligence
James Clapper reacts to White House press secretary Sarah Sanders
saying he and other former intelligence officials should be
investigated after special counsel Robert Mueller did not establish
collusion between the
Tr…\",\"url\":\"http://us.cnn.com/videos/politics/2019/03/26/james-clapper-reponse-mueller-report-sarah-sanders-criticism-bts-ac360-vpx.cnn\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190325211210-james-clapper-ac360-03252019-super-tease.jpg\",\"publishedAt\":\"2019-03-28T20:08:43.1736236Z\",\"content\":\"Chat
with us in Facebook Messenger. Find out what's happening in the world
as it
unfolds.\"},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Maegan
Vazquez, CNN\",\"title\":\"Trump set for first rally since Mueller
investigation ended\",\"description\":\"President Donald Trump, making
his first appearance before supporters since Robert Mueller ended his
investigation, is set to speak during a rally in Grand Rapids,
Michigan Thursday
night.\",\"url\":\"http://us.cnn.com/2019/03/28/politics/donald-trump-grand-rapids-rally/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190321115403-07-donald-trump-lead-image-super-tease.jpg\",\"publishedAt\":\"2019-03-28T19:49:26Z\",\"content\":\"Washington
(CNN)President Donald Trump, making his first appearance before
supporters since Robert Mueller ended his investigation, is set to
speak during a rally in Grand Rapids, Michigan Thursday
night.\r\nThe rally follows a chaotic week in Washington, preci…
[+2099
chars]\"},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Katelyn
Polantz, CNN\",\"title\":\"Judge orders Justice Dept. to turn over
Comey memos\",\"description\":\"A federal judge has ordered that the
James Comey memos are turned over, in a court case brought by CNN and
other media organizations for access to the documents memorializing
former FBI Director's interactions with President Donald
Trump.\",\"url\":\"http://us.cnn.com/2019/03/28/politics/james-comey-memo-lawsuit/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/181209143047-comey-1207-super-tease.jpg\",\"publishedAt\":\"2019-03-28T19:14:45Z\",\"content\":\"Washington
(CNN)A federal judge has ordered that the Justice Department and FBI
submit James Comey's memos in full to the court under seal, in a court
case brought by CNN and other media organizations for access to the
documents memorializing the former FBI d… [+1043
chars]\"},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Clare
Foran and Manu Raju, CNN\",\"title\":\"Pelosi calls AG's summary of
Mueller report 'arrogant'\",\"description\":\"House Speaker Nancy
Pelosi on Thursday criticized Attorney General William Barr's summary
of special counsel Robert Mueller's report, calling it
\\"condescending\\" and \\"arrogant\\" and saying \\"it wasn't
the right thing to
do.\\"\",\"url\":\"http://us.cnn.com/2019/03/28/politics/pelosi-mueller-report-congress-barr-summary/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190328130240-02-nancy-pelosi-03282019-super-tease.jpg\",\"publishedAt\":\"2019-03-28T18:48:25Z\",\"content\":null},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Analysis
by Chris Cillizza, CNN Editor-at-large\",\"title\":\"The 43 most
outrageous lines from Donald Trump's phone interview with Sean
Hannity\",\"description\":\"There's no \\"reporter\\" that President
Donald Trump likes more than Fox News' Sean Hannity -- largely due to
Hannity's unwavering, puppy dog-like support for the President. Trump
likes to reward people who play nice with him, which brings us to the
45-minute
ph…\",\"url\":\"http://us.cnn.com/2019/03/28/politics/sean-hannity-donald-trump-mueller/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190328140149-01-hannity-trump-file-super-tease.jpg\",\"publishedAt\":\"2019-03-28T18:44:21Z\",\"content\":\"(CNN)There's
no \\"reporter\\" that President Donald Trump likes more than Fox
News' Sean Hannity -- largely due to Hannity's unwavering, puppy
dog-like support for the President. Trump likes to reward people who
play nice with him, which brings us to the 45-minu… [+14785
chars]\"},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":null,\"title\":\"Puerto
Rico Gov.: I'll punch the bully in the mouth - CNN
Video\",\"description\":\"In an exclusive interview with CNN, Puerto
Rico Governor Ricardo Rosselló said he would not sit back and allow
his officials to be bullied by the White
House.\",\"url\":\"http://us.cnn.com/videos/politics/2019/03/28/ricardo-rossello-trump-bully-puerto-rico-sot-vpx.cnn\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190328123504-puerto-rico-gov-ricardo-rosello-super-tease.jpg\",\"publishedAt\":\"2019-03-28T18:08:33.7312458Z\",\"content\":\"Chat
with us in Facebook Messenger. Find out what's happening in the world
as it
unfolds.\"},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Jeremy
Herb, Manu Raju and Ted Barrett, CNN\",\"title\":\"Jared Kushner
interviewed by Senate Intelligence
Committee\",\"description\":\"President Donald Trump's son-in-law
Jared Kushner returned to the Senate Intelligence Committee for a
closed door interview Thursday as part of the committee's Russia
investigation.\",\"url\":\"http://us.cnn.com/2019/03/28/politics/jared-kushner-senate-intelligence/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/180302124221-30-jared-kushner-super-tease.jpg\",\"publishedAt\":\"2019-03-28T16:21:29Z\",\"content\":null},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Jeremy
Herb and Laura Jarrett, CNN\",\"title\":\"Mueller report more than 300
pages, sources say\",\"description\":\"Special counsel Robert
Mueller's confidential report on the Russia investigation is more than
300 pages, according to a Justice Department official and a second
source with knowledge of the
matter.\",\"url\":\"http://us.cnn.com/2019/03/28/politics/mueller-report-pages/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/190324130054-05-russia-investigation-0324-super-tease.jpg\",\"publishedAt\":\"2019-03-28T15:52:01Z\",\"content\":null},{\"source\":{\"id\":\"cnn\",\"name\":\"CNN\"},\"author\":\"Jim
Acosta and Kevin Liptak, CNN\",\"title\":\"Exclusive: Puerto Rico
governor warns White House over funding\",\"description\":\"Tensions
are escalating between President Donald Trump and Puerto Rico's
governor over disaster relief efforts that have been slow in coming
for the still-battered island after Hurricane
Maria.\",\"url\":\"http://us.cnn.com/2019/03/28/politics/ricardo-rossell-donald-trump-puerto-rico-funding/index.html\",\"urlToImage\":\"https://cdn.cnn.com/cnnnext/dam/assets/180920230539-pr-storm-of-controversy-rossello-trump-super-tease.jpg\",\"publishedAt\":\"2019-03-28T15:19:39Z\",\"content\":null}]}",
"trace-redirects"
["https://newsapi.org/v2/top-headlines?sources=cnn&apiKey=a688e6494c444902b1fc9cb93c61d687"]}
I'd like to extract to extract the URLs from the returned JSON payload, I've tried this:
(defn fetch_headlines [source]
(let [articlesUrl (str "https://newsapi.org/v2/top-headlines?sources="
source
"&apiKey=a688e6494c444902b1fc9cb93c61d697")]
(-> articlesUrl
client/get
generate-string
parse-string
(get-in ["source" "url"]))))
But I get a nil result, any ideas?
SOLUTION based on user feedback:
(defn fetch-headlines [source]
(let [articlesUrl (str "https://newsapi.org/v2/top-headlines?sources="
source
"&apiKey=a688e6494c444902b1fc9cb93c61d697")]
(-> articlesUrl
client/get
:body
parse-string
(get-in ["articles" 0 "url"]))))
What you need is inside the body key, but the value corresponding to that key is still a string and not yet a clojure map. When you look for source, you're getting nil back because that key doesn't exist (it should be inside body, after correctly parsing the string into json).
Once you've properly parsed the body value, it should be something like:
(let [index-of-article 0]
(get-in response ["body" "articles" index-of-article "url"]))
where index-of-article is the positional index of the article you want, since articles contains a vector of articles.

Difference between duration and duration_in_traffic in Google Directions API Response

After working with the Google Directions API for a project I found multiple responses with a (much) shorter value in duration_in_traffic than duration. An example extract from one of the responses i got:
"duration": {
"text": "23 mins",
"value": 1374
},
"duration_in_traffic": {
"text": "16 mins",
"value": 941
},
"end_address": "2868 Mission St, San Francisco, CA 94110, USA",
"end_location": {
"lat": 37.7522994,
"lng": -122.4184684
},
"start_address": "O'Farrell St & Powell St, San Francisco, CA 94102, USA",
"start_location": {
"lat": 37.78640559999999,
"lng": -122.4082846
},
This doesn’t seem to make much sense to me, since i assumed duration is simply the duration without traffic, while duration_in_traffic obviously incorporates traffic conditions. I found an answer on a different thread, but the person answering provided no source to back up his or her claim/observation. Is there more information about the duration response field out there besides the documentation itself, which just describes it as “[indicating] the total duration of this leg”? Is there a source stating that it actually is the average time for that route? And what is the difference between duration and duration_in_traffic?
After searching for more information about the difference between these two fields I came across this thread on the google issue tracker. There it is explained that the value in duration "takes into consideration historical data [...]", while duration_in_traffic "takes into account live traffic data in relation to your departure time". While this doesn't fully explain how the duration value is calculated, it at least extends the official documentation and confirms that historical data is used for the duration value. This also seems to be the only reliable information about the duration field on the web besides the official documentation which isn't very in depth.

Creating a list of JSON files only with only one component of the list

I have 4 json files spread into to folders: folder1 and folder2. Each json file contains the date, the body and the title.
folder1.json:
{"date": "December 31, 1989, Sunday, Late Edition - Final", "body": "Frigid temperatures across much of the United States this month sent demand for heating oil soaring, providing a final upward jolt to crude oil prices. That's assuming the economy performs as expected - about 1 percent growth in G.N.P. The other big uncertainty is the U.S.S.R. If their production drops more than 4 percent, prices could stengthen. ", "title": "Prospects;"}
{"date": "December 31, 1989, Sunday, Late Edition - Final", "body": "DATELINE: WASHINGTON, Dec. 30 For years, experts have dubbed Czechoslovakia's spy agency the ''two Czech'' service. Agents of the Office for the Protection of State Secrets got one check from Prague, the pun goes, and another from their real bosses at K.G.B. headquarters in Moscow. Roy Godson, head of the Washington-based National Strategy Information Center and a well-known intelligence scholar, called any democratic change ''a net loss'' for Soviet intelligence. But he cautioned against euphoria. ''The Soviets wouldn't have relied on just official cooperation,'' he said. ''It would be surprising if they haven't unilaterally penetrated friendly services with their own agents, too.'' ", "title": "Upheaval in the East: Espionage;"}
folder2.json:
{"date": "December 31, 1989, Sunday, Late Edition - Final", "body": "SURVIVING the decline in the economy will be the overriding issue for 1990, say leaders of the county's business community. But facing business owners are numerous problems, from taxes and regulations at all levels of government to competition from other businesses in and out of Westchester. Successful Westchester business owners will face and overcome these risks and obstacles. Westchester is a land of opportunity for the business owner. ", "title": "Coping With the Economic Prospects of 1990"}
{"date": "December 29, 1989, Friday, Late Edition - Final", "body": "Eastern Airlines said yesterday that it was laying off 600 employees, mostly managers, and cutting wages by 10 percent or 20 percent for about half its work force. Thomas J. Matthews, Eastern's senior vice president of human resources, estimated that the measures would save the carrier about $100 million a year. Eastern plans to rebuild by making Atlanta its primary hub and expects to operate about 75 percent of its flights from there. ", "title": "Eastern Plans Wage Cuts, 600 Layoffs"}
I will like to create a common list of all these json files but only with the body of each article. So far I am trying the following:
json1 <- lapply(readLines("folder1.json"), fromJSON)
json2 <- lapply(readLines("folder2.json"), fromJSON)
jsonl <- list(json1$body, json2$body)
But it is not working. Any suggestions?
Andres Azqueta
Solution:
You need to derence the the fromJSON(), in the sapply() to only retrieve the body.
fromJSON()$body
Note: I am assuming the file format from you previous question
The point being the file format is sudo JSON, hence the modified fromJSON() call below.
OK, Let step through an example:
Stage 1: Concatenate JSON files into 1
filelist <- c("./data/NYT_1989.json", "./data/NYT_1990.json")
newJSON <- sapply(filelist, function(x) fromJSON(sprintf("[%s]", paste(readLines(x), collapse = ",")), flatten = FALSE))
newJSON[2]# Extract bodies
newJSON[5]# Extract bodies
Output
filelist <- c("./data/NYT_1989.json", "./data/NYT_1990.json")
> newJSON <- sapply(filelist, function(x) fromJSON(sprintf("[%s]", paste(readLines(x), collapse = ",")), flatten = FALSE))
> newJSON[2]# Extract bodies
[[1]]
[1] "Frigid temperatures across much of the United States this month sent demand for heating oil soaring, providing a final upward jolt to crude oil prices. Some spot crude traded at prices up 40 percent or more from a year ago. Will these prices hold? Five experts on oil offer their views. That's assuming the economy performs as expected - about 1 percent growth in G.N.P. The other big uncertainty is the U.S.S.R. If their production drops more than 4 percent, prices could stengthen. "
[2] "DATELINE: WASHINGTON, Dec. 30 For years, experts have dubbed Czechoslovakia's spy agency the ''two Czech'' service. But he cautioned against euphoria. ''The Soviets wouldn't have relied on just official cooperation,'' he said. ''It would be surprising if they haven't unilaterally penetrated friendly services with their own agents, too.'' "
[3] "SURVIVING the decline in the economy will be the overriding issue for 1990, say leaders of the county's business community. Successful Westchester business owners will face and overcome these risks and obstacles. Westchester is a land of opportunity for the business owner. "
> newJSON[5]# Extract bodies
[[1]]
[1] "Blue temperatures across much of the United States this month sent demand for heating oil soaring, providing a final upward jolt to crude oil prices. Some spot crude traded at prices up 40 percent or more from a year ago. Will these prices hold? Five experts on oil offer their views. That's assuming the economy performs as expected - about 1 percent growth in G.N.P. The other big uncertainty is the U.S.S.R. If their production drops more than 4 percent, prices could stengthen. "
[2] "BLUE1: WASHINGTON, Dec. 30 For years, experts have dubbed Czechoslovakia's spy agency the ''two Czech'' service. But he cautioned against euphoria. ''The Soviets wouldn't have relied on just official cooperation,'' he said. ''It would be surprising if they haven't unilaterally penetrated friendly services with their own agents, too.'' "
[3] "GREEN4 the decline in the economy will be the overriding issue for 1990, say leaders of the county's business community. Successful Westchester business owners will face and overcome these risks and obstacles. Westchester is a land of opportunity for the business owner. "
Stage 2: Concatenate and extract the body from all files...
Look for the reference to fromJSON()$body in code line...
filelist <- c("./data/NYT_1989.json", "./data/NYT_1990.json")
newJSON <- sapply(filelist, function(x) fromJSON(sprintf("[%s]", paste(readLines(x), collapse = ",")), flatten = FALSE)$body)
newJSON
Output
> filelist <- c("./data/NYT_1989.json", "./data/NYT_1990.json")
> newJSON <- sapply(filelist, function(x) fromJSON(sprintf("[%s]", paste(readLines(x), collapse = ",")), flatten = FALSE)$body)
> newJSON
./data/NYT_1989.json
[1,] "Frigid temperatures across much of the United States this month sent demand for heating oil soaring, providing a final upward jolt to crude oil prices. Some spot crude traded at prices up 40 percent or more from a year ago. Will these prices hold? Five experts on oil offer their views. That's assuming the economy performs as expected - about 1 percent growth in G.N.P. The other big uncertainty is the U.S.S.R. If their production drops more than 4 percent, prices could stengthen. "
[2,] "DATELINE: WASHINGTON, Dec. 30 For years, experts have dubbed Czechoslovakia's spy agency the ''two Czech'' service. But he cautioned against euphoria. ''The Soviets wouldn't have relied on just official cooperation,'' he said. ''It would be surprising if they haven't unilaterally penetrated friendly services with their own agents, too.'' "
[3,] "SURVIVING the decline in the economy will be the overriding issue for 1990, say leaders of the county's business community. Successful Westchester business owners will face and overcome these risks and obstacles. Westchester is a land of opportunity for the business owner. "
./data/NYT_1990.json
[1,] "Blue temperatures across much of the United States this month sent demand for heating oil soaring, providing a final upward jolt to crude oil prices. Some spot crude traded at prices up 40 percent or more from a year ago. Will these prices hold? Five experts on oil offer their views. That's assuming the economy performs as expected - about 1 percent growth in G.N.P. The other big uncertainty is the U.S.S.R. If their production drops more than 4 percent, prices could stengthen. "
[2,] "BLUE1: WASHINGTON, Dec. 30 For years, experts have dubbed Czechoslovakia's spy agency the ''two Czech'' service. But he cautioned against euphoria. ''The Soviets wouldn't have relied on just official cooperation,'' he said. ''It would be surprising if they haven't unilaterally penetrated friendly services with their own agents, too.'' "
[3,] "GREEN4 the decline in the economy will be the overriding issue for 1990, say leaders of the county's business community. Successful Westchester business owners will face and overcome these risks and obstacles. Westchester is a land of opportunity for the business owner. "
require(RJSONIO)
json_1<- fromJSON("~/folder1/1.json")
json_2<- fromJSON("~/folder2/2.json")
jsonl <- list(json1$body, json2$body)

Creating a corpus out of texts stored in JSON files in R

I have several JSON files with texts in grouped into date, body and title. As an example consider:
{"date": "December 31, 1990, Monday, Late Edition - Final", "body": "World stock markets begin 1991 facing the threat of a war in the Persian Gulf, recessions or economic slowdowns around the world, and dismal earnings -- the same factors that drove stock markets down sharply in 1990. Finally, there is the problem of the Soviet Union, the wild card in everyone's analysis. It is a country whose problems could send stock markets around the world reeling if something went seriously awry. With Russia about to implode, that just adds to the risk premium, said Mr. Dhar. LOAD-DATE: December 30, 1990 ", "title": "World Markets;"}
{"date": "December 30, 1992, Sunday, Late Edition - Final", "body": "DATELINE: CHICAGO Gleaming new tractors are becoming more familiar sights on America's farms. Sales and profits at the three leading United States tractor makers -- Deere & Company, the J.I. Case division of Tenneco Inc. and the Ford Motor Company's Ford New Holland division -- are all up, reflecting renewed agricultural prosperity after the near-depression of the early and mid-1980's. But the recovery in the tractor business, now in its third year, is fragile. Tractor makers hope to install computers that can digest this information, then automatically concentrate the application of costly fertilizer and chemicals on the most productive land. Within the next 15 years, that capability will be commonplace, predicted Mr. Ball. LOAD-DATE: December 30, 1990 ", "title": "All About/Tractors;"}
I have three different newspapers with separate files containing all the texts produced for the period 1989 - 2016. My ultimate goal is to combine all the texts into a single corpus. I have done it in Python using the pandas library and I am wondering if it could be done in R similarly. Here is my code with the loop in R:
for (i in 1989:2016){
df0 = pd.DataFrame([json.loads(l) for l in open('NYT_%d.json' % i)])
df1 = pd.DataFrame([json.loads(l) for l in open('USAT_%d.json' % i)])
df2 = pd.DataFrame([json.loads(l) for l in open('WP_%d.json' % i)])
appended_data.append(df0)
appended_data.append(df1)
appended_data.append(df2)
}
Use jsonlite::stream_in to read your files and jsonlite::rbind.pages to combine them.
There many options in R to read json file and convert them to a data.frame/data.table.
Here one using jsonlite and data.table:
library(data.table)
library(jsonlite)
res <- lapply(1989:2016,function(i){
ff <- c('NYT_%d.json','USAT_%d.json' ,'WP_%d.json')
list_files_paths <- sprintf(ff,i)
rbindlist(lapply(list_files_paths,fromJSON))
})
Here res is a list of data.table. If you want to aggregate all data.table in a single data.table:
rbindlist(res)
Use ndjson::stream_in to read them in faster and flatter than jsonlite::stream_in :-)

Angular.js parse html tags in JSON

Is it possible to parse html tags in a JSON value? Possibly through a filter? I have the following JSON.
{
"title" : "Auto Donation Program",
"shortname" : "auto_donation_program",
"summary": "Donated vehicles find new homes through this program. Recipients are eligible to apply if they have been actively participating at Vineyard Cincinnati or The Healing Center under the guidelines of the program for six months.",
"description" : "<h2>Give your automobile to a new home to help a family in need</h2><p>Please contact Deena Casagrande at (513) 346-4080 Ext. 207 to make arrangements for auto donations. Please do not drop your car off in the parking lot.</p><h2>Tax Benefits</h2><p>It seems that every non-profit these days is encouraging you to donate your vehicle to charity and \"get a tax deduction.\" But there’s a simple distinction between donating your car to The Healing Center versus donating it almost anywhere else.</p><p>As of January 1, 2005, the rules on how much you can write off your taxes were tightened. If the organization sells your car, as most do, you can deduct only the amount they sold it for--and they may sell it for far less than it’s worth. However, if the organization gives your car to someone who will drive it, as The Healing Center does, you can claim full Blue Book value--a significant difference on your taxes. (It’s important to note that when you donate a vehicle, you receive a tax deduction, not a tax credit.)</p><h2>So where does your car end up? </h2><p>Those on the receiving end of The Healing Center’s auto donation program must fill out a detailed questionnaire, meet the eligibility requirements of the program, and be approved by the Benevolence Review Team. Vehicles are given to single parent families or individuals needing transportation for employment or who are enrolled in school to obtain employment.</p>"
}
Displayed in my template as:
<p>{{service.description}}</p>
This worked for me:
<div ng-bind-html="'{{service.description}}' | to_trusted"></div>
Filter
angular.module('app')
.filter('to_trusted', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);