I am using NYTimes API to scrap news articles for my text analysis. Here is the code.
from nytimesarticle import articleAPI
api = articleAPI('<API key>')
articles = api.search(q = 'President',
fq = {'source':['Reuters','AP', 'The New York Times']},
begin_date = 20110829,
end_date = 20161203)
print ("the response is ", articles)
However, it does not return any results. This is the sample response with null dataset:
{'response': {'meta': {'offset': 0, 'time': 227, 'hits': 0}, 'docs':
[]}, 'status': 'OK', 'copyright': 'Copyright (c) 2013 The New York
Times Company. All Rights Reserved.'}
Should there be any additional paremeters when sending the request
I actually was using a completely different API in my initial code. Using "requests" API solved the problem here
uri = "http://api.nytimes.com/svc/archive/v1/"+str(year)+"/"+str(month)+".json?api-key=<>"
resp = requests.get(uri)
Related
I'm new to the SurveyMonkey API (and relatively new to Python in general).
I'm trying to retrieve the contacts that have either bounced or opted out (with 2 separate calls). This code was working last week (at that time, the query parameters were permissible on the contacts/bulk endpoint and they are now only on the contacts endpoint).
The code below is only returning active contacts (the default). It does 'accept' when I change the per_page parameter but I'm not sure why the status isn't working.
Where am I going wrong?
token = <our_token>
client = requests.session()
headers = {
"Authorization": "Bearer %s" % token,
"Content-Type": "application/json"
}
HOST = "https://api.surveymonkey.com"
EMAIL_ENDPOINT = "/v3/contacts"
OPTOUT = '?status=optout'
PER_PAGE = '&per_page=1000'
optout_url = "%s%s%s%s" % (HOST, EMAIL_ENDPOINT, OPTOUT, PER_PAGE)
optout_api = client.get(optout_url, headers=headers).json()
nm. Heard back from SurveyMonkey and it's an issue on their end.
Earlier i have used Dropbox api on personal user account and all goes very fine.
Now, i need to do the same, but this time account is a business account user. I have tried for hours but can't find a working way to upload the file.
Here is my code that i tried:
objDHTTP = New Chilkat.Http
objDHTTP.UnlockComponent("")
objDHTTP.HeartbeatMs = 125
objDHTTP.ConnectTimeout = 60
objDHTTP.ReadTimeout = 60
objDJSON = New Chilkat.JsonObject
objDJSON.AppendString("path", "/test.pdf")
objDJSON.AppendString("mode", "overwrite")
objDJSON.AppendBool("autorename", False)
objDJSON.AppendBool("mute", True)
objDRequest = New Chilkat.HttpRequest
objDRequest.UsePost()
objDRequest.Path = "/2/files/upload"
objDRequest.AddHeader("Content-Type", "application/octet-stream")
objDRequest.AddHeader("Dropbox-API-Select-User", "dbmid:member_id") 'Note-1
objDRequest.AddHeader("Authorization", "Bearer auth_token") 'Note-2
objDRequest.AddHeader("Dropbox-API-Arg", objDJSON.Emit)
objDRequest.StreamBodyFromFile(strLocalFile)
objDResponse = objDHTTP.SynchronousRequest("content.dropboxapi.com", 443, True, objDRequest)
objDJSON.Dispose()
objDJSON = Nothing
If (objDResponse Is Nothing) Then
strDBReturn = "Call failed!"
Else
strDBReturn = objDResponse.BodyStr.Trim
objDResponse.Dispose()
objDResponse = Nothing
End If
objDRequest.Dispose()
objDRequest = Nothing
Code is in vb.net and i use chilkat libray for http and json part.
but it's very easy to understand the code.
Note-1: i have set the header to select member.
Note-2: first i tried Dropbox API, then i am tring Dropbox Business API
it's shows in the response that file is upload and also shows the same path as the http request.. but i can't find the file in the Dropbox (from browser) :(
Here is the DB Response Example:
{"name": "test1.pdf", "path_lower": "/test1.pdf", "path_display": "/test1.pdf", "id": "id:7fQPQ7pubtAAAAAAAAAAFQ", "client_modified": "2018-10-01T13:46:24Z", "server_modified": "2018-10-01T13:46:24Z", "rev": "cee6f9f90", "size": 204181, "content_hash": "318bc8a4b25c3c319b558dda011a8e837caa0dee2b84e1c7deb0d0405bad1bf0"}
any help will be highly appreciated..
thanks in advance
best regards
I tried to plot some graphs in Linqpad with with "Util.RawHtml()" and "Dump()" but it is not working with this example from amcharts.com. I created a string variable including all the HTML source code but the result is not working.
string html = "";
using (System.Net.WebClient client = new System.Net.WebClient ())
{
html = client.DownloadString(#"http://pastebin.com/raw/pmMMwXhm");
}
Util.RawHtml(html).Dump();
Later versions of LinqPad 5 now support charting out of the box with Util.Chart. You can see the samples in the Samples Tab (next to My Queries) under
LINQPad Tutorial&Reference
Scratchpad Features
Charting with Chart
The following script is the Chart() - dual scale sample:
// Each y-series can have a different series type, and can be assigned to the secondary y-axis scale on the right.
var customers = new[]
{
new { Name = "John", TotalOrders = 1000, PendingOrders = 50, CanceledOrders = 20 },
new { Name = "Mary", TotalOrders = 1300, PendingOrders = 70, CanceledOrders = 25 },
new { Name = "Sara", TotalOrders = 1400, PendingOrders = 60, CanceledOrders = 17 },
};
customers.Chart (c => c.Name)
.AddYSeries (c => c.TotalOrders, Util.SeriesType.Spline, "Total")
.AddYSeries (c => c.PendingOrders, Util.SeriesType.Column, "Pending", useSecondaryYAxis:true)
.AddYSeries (c => c.CanceledOrders, Util.SeriesType.Column, "Cancelled", useSecondaryYAxis:true)
.Dump();
As I understand it, this will not work because the html contains scripts that will not be executed.
As an alternative, you can still use the old (and deprecated) google charts api, eg
var link = #"http://chart.apis.google.com/chart?chxt=y&chbh=a&chs=300x225&cht=bvg&chco=A2C180,3D7930&chd=t:10,20,30,40,50,60|30,35,40,45,55,60&chtt=Sample";
Util.Image (link).Dump();
or see
http://blog.divebomb.org/2012/11/dumping-charts-in-linqpad/
Not sure if it's the answer you're after but there may be value in looking at the DisplayWebPage method on the Util class in Linqpad. This correctly rendered your chart in the result window, (although there was a script error). Obviously, this may not solve your underlying issue.
I used version 5.10.00 to test this.
I am integrating
rails application to Quickbooks online
using API.
Use gem Quickbooks-ruby
But want to add discount, add taxes into invoice but not success even not found how to pass in API.
invoice = Quickbooks::Model::Invoice.new
invoice.customer_id = 1
invoice.txn_date = Date.civil(2014, 3, 27)
invoice.doc_number = "001"
transaction_tax = Quickbooks::Model::TransactionTaxDetail.new
# Point to a saved tax code in QBO, e.g. this points to id = 2,
# which is a NYC tax code saved on QBO account = 10% sales tax
transaction_tax.txn_tax_code_id = 2
transaction_tax.total_tax = 134.10
invoice.txn_tax_detail = transaction_tax
sales_line_item = Quickbooks::Model::InvoiceLineItem.new
sales_line_item.amount = 1490
sales_line_item.description = "CCM ice skates"
sales_line_item.sales_item! do |detail|
detail.unit_price = 149
detail.quantity = 10
detail.item_id = 1 # Item ID here
detail.tax_code_id = 'TAX' # for US must be 'NON' or 'TAX'
end
discount_line_item = Quickbooks::Model::InvoiceLineItem.new
discount_line_item.amount = 149
discount_line_item.discount_item! do |detail|
detail.discount_percent = 10
detail.percent_based = true
detail.discount_account_id = 99
end
invoice.line_items << sales_line_item
invoice.line_items << discount_line_item
service = Quickbooks::Service::Invoice.new
service.access_token = OAuth::AccessToken.new($qb_oauth_consumer, "token", "secret")
service.company_id = "9991111222"
created_invoice = service.create(invoice)
There should be something like JAXB in ruby for object serialization/deserialization.
From the following link, you can download QB endpoint definations and data class defination(as XSD). You need to generate data classes from it.
https://developer.intuit.com/docs/#api/deki/files/2466/v3.1_dataservices.zip
Then using any standard ruby based OAuth lib, you can make call to QB API Endpoints.
You can use the setter methods of the data class( in your case - invoice ) to populate data/to construct the payload. ( I don't have any ready example of this. But I guess it is not hard to find in net)
For doc, you can refer the following two links.
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice#DiscountLineDetail
Thanks
I have to send mutiple events with one .ics file using ASpnetMail Class in vb.net. and i went throgh the ASpnetMail documention but i didn't get any clue..
Please suggest me...
Reagrds
Pankaj Pareek.
What you will want to do, is create a 2nd event, and add it to the ical.Events collection.
Here is a code example that a customer needed, for streaming the iCal to the browser. You could have just of easily of added it to an EmailMessage object, and sent it in an email.
iCalendar ical = new iCalendar();
ical.Method.Value = "Publish";
//create the 1st event
EventComponent e1 = new EventComponent();
e1.Summary.Text = "Last Day for Dropping Winter Term Course with \"W\"";
e1.Description.Text = "Last Day for Dropping Winter Term Course with \"W\"";
DateTime startAt = new DateTime( 2009, 01, 12, 8, 0, 0 );
e1.DateStart.Date = startAt;
e1.DateEnd.Date = startAt.AddHours( 9 );
ical.Event = e1;
//create the 2nd event
EventComponent e2 = new EventComponent();
e2.Summary.Text = "Martin Luther King Jr. Holiday";
e2.Description.Text = "Martin Luther King Jr. Holiday";
DateTime startAt2 = new DateTime( 2009, 01, 16, 8, 0, 0 );
e2.DateStart.Date = startAt2;
e2.DateEnd.Date = startAt2.AddHours( 9 );
//add it to the Events collection
ical.Events.Add( e2 );
//save to a file
ical.WriteToFile( "c:\\temp\\somefile.ics");
//stream the file to the browser
Response.ClearHeaders();
Response.ContentType = "text/calendar";
Response.AppendHeader( "Filename", "events.ics");
Response.AppendHeader("Content-Disposition", "attachment;filename=events.ics");
ical.WriteToStream( Response.OutputStream );
Response.Flush();
Response.End();
Does that help?
--Dave