I am trying to use zenpy to get information on tickets created or modified in the last week. This is the code I am using:
stream_status = False #Exit condition
while(stream_status==False):
print(start_date)
all_tickets = zendesk.tickets.incremental(start_time=start_date, include=['users','organizations'])
print(len(all_tickets))
print(all_tickets.end_time)
for ticket in all_tickets:
#grab ticket fields and store them in a Dataframe
df.loc[len(df)] = [ticket_id,created_at,requester,organization,product,subject,assignee,status,priority,opened_at,opened_by,solved_at,solved_by,closed_at,closed_by]
count +=1
print(count,ticket_id)
start_date = all_tickets.end_time
stream_status = all_tickets.end_of_stream
print(start_date,stream_status)
today = datetime.now().strftime("%Y%m%d%H%M")
df.to_excel('Ticket_report{0}.xlsx'.format(today))
Now there are several issues here. The date is calculated correctly and it's indeed 7 days ago. But the tickets I am getting are going back to at least April and they were definitely not been modified since. I stopped it at this point cause we have thousands of tickets.
Also, the incremental method returns a max of 1000 ticket objects, but even after 1000 the loop doesn't seem to restart (print statement at the end doesn't trigger). I am not sure I am using the stream_status flag correctly. Any advice is more than welcome. Thank you!
Zenpy documentation on incremental can be found here: http://docs.facetoe.com.au/zenpy.html#incremental-exports
It was an API issue after all.
For anyone facing similar issues, turns out that the start date is compared against the generated_timestamp instead of the updated_at or created_at fields. Updated_at holds the last action that generated a ticket event(e.g. change) but generated_timestamp is updated every time the ticket is affected even from the system. That leads to grabbing tickets updated or created before the input date. A solution for that is to filter out the results after the call:
all_tickets = zendesk_client.incremental(start_time=start_date)
accurate_tickets = [ticket for ticket in all tickets if parser.parse(ticket.updated_at) > start_date]
Not very sure why they designed the API like this, seems a bit wrong, but that's how it works unfortunately.
Source: https://developer.zendesk.com/documentation/ticketing/managing-tickets/using-the-incremental-export-api/#excluding-system-updated-tickets-time-based-exports
Related
Use-Case : I am having an Integration in place that creates multiple Vendor Bills in Netsuite for every 5 minutes. I want to export the vendor bills created in those time to FTP. For that I need to create a saved search that can preview vendor bills created in past five minutes. Do we have any criteria in Netsuite Save Search to accomplish that ?
Please advise.
A Netsuite inconsistency.
I keep a snippet for this.
function toNSLegalDatetime(date){
var formatted = <string>format.format({value:date, type:format.Type.DATETIMETZ});
return formatted.replace(/(:\d{2}):\d{2}/, '$1');
}
Then you can do:
const lastDT = new Date(Date.now() - 5*60000)); // 5 minutes ago
search.create({
type:'vendorbill',
filters:[
search.createFilter({name:'datecreated', operator:search.Operator.ONORAFTER, values:toNSLegalDatetime(lastDT)}),
...
BUT
timing like this is very tricky because small delays in timing could cause you to miss transactions. If you can keep track of the last internalid reported your next search could just use that and it wouldn't matter what the lag was.
search.createFilter({name:'internalidnumber', operator:search.Operator.GREATERTHAN, values:lastIdReported})
It seems to be a simple question but I have a hard time to find an answer to it. I already have a project with several parameters (project and database parameters). I would like to obtain the LCA results for several scenarios with my parameters having different values each time. I was thinking of the following simple procedure:
change the parameters' value,
update the exchanges in my project,
calculate the LCA results.
I know that the answer should be in the documentation somewhere, but I have a hard time to understand how I should apply it to my ProjectParameters, DatabaseParameters and ActivityParameters.
Thanks in advance!
EDIT: Thanks to #Nabla, I was able to come up with this:
For ProjectParameter
for pjparam in ProjectParameter.select():
if pjparam.name=='my_param_name':
break
pjparam.amount = 3
pjparam.save()
bw.parameters.recalculate()
For DatabaseParameter
for dbparam in DatabaseParameter.select():
if dbparam.name=='my_param_name':
break
dbparam.amount = 3
dbparam.save()
bw.parameters.recalculate()
For ActivityParameter
for param in ActivityParameter.select():
if param.name=='my_param_name':
break
param.amount = 3
param.save()
param.recalculate_exchanges(param.group)
You could import DatabaseParameter and ActivityParameter iterate until you find the parameter you want to change, update the value, save it and recalculate the exchanges. I think you need to do it in tiers. First you update the project parameters (if any) then the database parameters that may depend on project parameters and then the activity parameters that depend on them.
A simplified case without project parameters:
from bw2data.parameters import ActivityParameter,DatabaseParameter
# find the database parameter to be updated
for dbparam in DatabaseParameter.select():
if (dbparam.database == uncertain_db.name) and (dbparam.name=='foo'):
break
dbparam.amount = 3
dbparam.save()
#there is also this method if foruma depend on something else
#dbparam.recalculate(uncertain_db.name)
# here updating the exchanges of a particular activity (act)
for param in ActivityParameter.select():
if param.group == ":".join(act.key):
param.recalculate_exchanges(param.group)
you may want to update all the activities in the project instead of a single one like in the example. you just need to change the condition when looping through the activity parameters.
I would like to provide one piece of content per day storing all items in dynamoDB. I will add new content from time to time but only one piece of content needs to be read per day.
It seems it's not recommended to have incremental Id as primary key on dynamoDB.
Here is what I have at the moment:
content_table
id, content_title, content_body, content_author, view_count
1b657df9-8582-4990-8250-f00f2194abe9, title_1, body_1, author_1, view_count_1
810162c7-d954-43ff-84bf-c86741d594ee, title_2, body_2, author_2, view_count_2
4fdac916-0644-4237-8124-e3c5fb97b142, title_3, body_3, author_3, view_count_3
The database will have a low rate of adding new item has I will add new content myself manually.
How can I get the item number XX without querying all the database in nodeJS ?
Should I switch back to a MySQL database ?
Should I use a homemade auto increment even if it's an anti pattern ?
Should I used a time-based uuid, and do a query like, get all ids, sort them, and get the number X in the array ?
Should I use a tool like http://www.stateful.co/ ?
Thanks for your help
I would make the date your hash key, you can then simply get the content from any particular day using GetItem.
date, content_title, content_body, content_author, view_count
20180208, title_1, body_1, author_1, view_count_1
20180207, title_2, body_2, author_2, view_count_2
20180206, title_3, body_3, author_3, view_count_3
If you think you might have more than one piece of content for any one day in future, you could add a datetime attribute and make this the range key
date, datetime, content_title, content_body, content_author, view_count
20180208, 20180208101010, title_1, body_1, author_1, view_count_1
20180208, 20180208111111, title_2, body_2, author_2, view_count_2
20180206, 20180208101010, title_3, body_3, author_3, view_count_3
Its then still very fast and simple to execute a Query to get the content for a particular day.
Note that due to the way DynamoDB distributes throughput, if you choose the second option, you might want to archive old content into another table.
I am trying to extract the data in the div with "" as className followed by p tag.
My html looks like this
<div class=""><p>I've been with USAA since 1981 - they've been a good, helpful company and easy to deal with except with making payments on their website. Every time I try to make a payment the website has a problem and I end up calling them. Today, I tried to make a credit card update (same account, different exp. date and code) before I made a payment. The website kept telling me it wouldn't accept the information.</p><p>I called the company to make the payment and was told the system had accepted the information but I couldn't make the payment until tomorrow because of the update. They refused to let me make my payment by phone. 4 times in the past 2 years it wouldn't accept my password, even after I confirmed it by - yes calling in. Other payments have not been accepted for unknown reasons - I've had to call them in. No point having a website if it doesn't work. I avoid calling because it takes so many steps to reach a live person. It's a minor complaint but it happens every time.</p></div></div>
I am using Beautifulsoup and my code to extarct this data is :
reviewAllList = [row.text for row in soup.find_all('div',attrs={"class" : ""})]
However, I am not able to extarct the correct data from the same. Is it that I am missing something? I am using Python 3.5.
Use lambda to find all divs with an empty class attribute andthe first child is a p
rows = [str(row.get_text(strip=True)) for row in soup.find_all(lambda tag: tag.name == "div" and ("class" not in tag.attrs or not len(" ".join(tag["class"]))) and tag.findChildren()[0].name == "p")]
You can just print the text only by saying.
sometxt = <div class=""><p>I've been with USAA since 1981 - they've been a good, helpful company and easy to deal with except with making payments on their website. Every time I try to make a payment the website has a problem and I end up calling them. Today, I tried to make a credit card update (same account, different exp. date and code) before I made a payment. The website kept telling me it wouldn't accept the information.</p><p>I called the company to make the payment and was told the system had accepted the information but I couldn't make the payment until tomorrow because of the update. They refused to let me make my payment by phone. 4 times in the past 2 years it wouldn't accept my password, even after I confirmed it by - yes calling in. Other payments have not been accepted for unknown reasons - I've had to call them in. No point having a website if it doesn't work. I avoid calling because it takes so many steps to reach a live person. It's a minor complaint but it happens every time.</p></div></div>
and now just print(sometxt.text)
if you're only looking for the div class= > "" <
You can print it by print(sometxt['class']) remember that you might have to itterate through your findAll with a for loop to do this.(if there's multiple class)
**row.text**
I assume you just want to get the text from the paragraphs.
You could do something like:
mydiv = soup.find("div", { "class" : "" })
for p in mydiv.find_all('p'):
text_list.append(p.get_text())
or
mydiv = soup.find("div", { "class" : "" })
text = mydiv.find('p').get_text()
Can not test right now, but from my experience with BS this should work fine.
Edit: tested and corrected it.
Im trying to create a customer deposit record in Netsuite using suitescript 1.0.
The original code I had in place which had been working perfectly up until the 2016.2 release broke it.
The update broke it, in that it would override the value submitted in the payment field and instantly make it the full amount of the sales order from the sales order ID. Which is not what we need it to do.
Original Code
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit');
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
After a reply on the Netsuite user group prompted me to use the {recordmode:'dynamic'} attributes I am getting a strange error..
Test Replacement Function which doesnt work
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit',{recordmode:'dynamic'});
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
The error message Im getting now is
Invalid salesorder reference key 1260 for customer .
The thing I dont get is how it is now considered NULL, when the value is hardcoded into this test script after I apply the {recordmode:'dynamic'} value.
Ive tried a wide variety of things, but as I dont have Netsuite support, its proving to be something I simply cant figure out.
Any hints, suggestions would be greatly appreciated as Ive been on this for several days
When you use dynamic the order you set fields makes a difference. So when you set the sales order prior to setting the customer you are actually getting the error message "Invalid salesorder reference key 1260 for customer blank"
What I do is create the customer deposit like:
var depRec = nlapiCreateRecord('customerdeposit', {entity:soRec.getFieldValue('entity'), salesorder:soId});
also setting the undeposited funds flag seems to be required (but not always for some reason) so since you are supplying an account id also do this:
depRec.setFieldValue('undepfunds', 'F');