I am trying to use the Todoist-API for Python. I found the official docs on the internet and downloaded the GitHub-Repo. Unfortunately I don't get out how to add a new task.
I do the normal login:
api = todoist.TodoistAPI(XYZ)
api.sync
Then I try to add a new task:
item = api.items.add('Task1')
It tells me I have to give two arguments: name and project_id:
item = api.items.add('Task1', 128501470)
Does anyone know where I could get all my projects IDs? I just want to use the Inbox-Project (default).
I'm not very familiar with this specific API, but considering you're using this api: https://github.com/doist/todoist-python, you can probably do something like:
response = api.sync()
projects = response['projects']
for project in projects:
print(project['name'] + '-' + project['id'])
Basically printing all the names and id's
Just open Todoist in a web browser and look at the address bar, it's right after "project", I beleive you need to truncate the first three or 4 characters though, click through a few projects and you'll see the project id's change.
To add them to the inbox the easiest way is to do the following:
from todoist.api import TodoistAPI
apiToken = 'your token"
todoist: TodoistAPI = TodoistAPI(api_token)
response = todoist.add_item("Item1")
todoist.sync()
todoist.commit()
You will have to refresh either the web page or your app to immediately see the new item
Related
I may be doing it the wrong way but I want, at first, to extract keyword traffic information like I did with TrafficEstimationService in the (now deprecated) AdWords API. My code looks like this (with some edits here and there):
# [... some initialization (clients, service accounts, etc.) bits here]
# fetch an instance of the Google Ads client
gc = GoogleAdsClient.load_from_storage(gads_credentials_file, version="v10")
# fetch an instance of the Google Ads service
gs = gc.get_service("GoogleAdsService")
# fetch an instance of the Geo Target Constant service
gtcs = gc.get_service("GeoTargetConstantService").geo_target_constant_path
# fetch an instance of the keyword plan idea service
ks = gc.get_service("KeywordPlanIdeaService")
# build the initial search request
rq = gc.get_type("GenerateKeywordIdeasRequest")
rq.customer_id = gads_account_id.replace("-", '')
rq.geo_target_constants = [gtcs(get_location_id(gads_country))]
rq.keyword_plan_network = (gc.enums.KeywordPlanNetworkEnum.GOOGLE_SEARCH_AND_PARTNERS)
rq.language = gs.language_constant_path(get_language_id(gads_language))
rq.keyword_annotation = gc.enums.KeywordPlanKeywordAnnotationEnum
if len(gads_keywords) > 0:
rq.keyword_seed.keywords.extend(gads_keywords)
# generate keyword ideas
keyword_ideas = ks.generate_keyword_ideas(request=rq)
rows = []
for idea in keyword_ideas:
rows.append({
"date": r,
"text": idea.text,
"competition_value": idea.keyword_idea_metrics.competition.name,
"avg_monthly_searches": idea.keyword_idea_metrics.avg_monthly_searches
})
So far, so good. I can specify location and language and (of course) they keywords to look for. At the end of this request, I have something like this (just printing the first list item):
{'date': '2022-08-09', 'text': 'zapatos', 'competition_value': 'MEDIUM', 'avg_monthly_searches': 301000}
The problem I have is I have been requested to ensure the match type is EXACT but looking at both the documentation and the source code for KeywordPlanIdeaService there is no trace of this parameter. That's why I assume I'm doing it wrong (or maybe I'm lacking something here). In any case, I'm a bit lost.
Can you tell me how can I specify this (if it can be done) or an alternate way to accomplish this?
The output will be what Google Ads now calls exact match (which really isn't that exact anymore) - I believe they don't give you searches for only the keyword as that isn't really an option in their advertising as well.
The avg. monthly searches you receive will be for the keyword + close variants, and if you want to check which variants are included you can using this: https://developers.google.com/google-ads/api/reference/rpc/v11/GenerateKeywordHistoricalMetricsResult
I have a Python script that I've been running for months that uses shareplum to update various columns of a SharePoint List using UpdateListItems(kind = 'Update'). It has suddenly stopped working and I've no idea why. I don't get any error messages but the changes I am trying to make are not showing up. Creating a new item is working fine, it's only when I try to update an existing list item. I use the Office365 version of SharePoint.
The List is relatively large with over 500 list items and over 100 columns. The maximum List ID is 1050.
I tested it on another smaller list and it works OK, so it must be an issue with this particular List.
I'd be really grateful if someone could help. Since I'm not getting any error messages I don't know how to check what could be wrong with it.
from shareplum import Site
from shareplum import Office365
authcookie = Office365('https://XXX.sharepoint.com', username= XXX, password= XXX).GetCookies()
site = Site('https://XXX.sharepoint.com/sites/XXX', authcookie=authcookie)
list_ = site.List('TestList')
my_data = [{'ID': '3', 'Title': 'TestTitle'}]
list_.UpdateListItems(data=my_data, kind='Update')
UPDATE: I printed off the result of the response which says '0x80070057', 'Bad parameter passed to Web Server Extensions. Check the information you entered and try again.' I'm not sure if this helps identify what the issue could be?
I am now able to update my List items using Office365-REST-Python-Client instead of shareplum, but still love to know what the issue with shareplum is.
Idk Python, but PowerShell/CSOM allows you to update the item after you have made the update. I'm assuming Shareplum is a wrapper for CSOM, so you should still have the ability to manually trigger the update.
I don't remember the code of the top of my head, but to manually update it it's something like this (in CSOM):
$listItem = get-pnplistitem -Identity 1 -list "Documents"
$listItem.Fields["Title"] = "New Title"
$listItem.Update()
$listItem.context.executeQuery()
So im pulling issues from our jira project and I need to replace url's with new formatted url's in the description.
old description contains the old sharepoint server URL's so I need to change them to our new online Sharepoint url.
I decided to use Python to make use of the atlassian plugin.
here is a version of how the description looks like in the jira issue currently:
Good day
we need a new validation on the External Reference when doing work pads or amending manually when we do refund, it seems that the user that updates this is using Tab or Enter and therefore the payment files fails ,
we need users to be validated while updating refund reference same way as we limited claims payments for updating invoice numbers
thank you
regards
*BRS & FRS:*
[BRS_FRS_PS_ACC_Payments_v20.0|http://portal.mycompany.local/mycompany/someproject/_layouts/15/start.aspx#/someproject/Forms/AllItems.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2Fsomeproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS&View=%7B9A71C976%2D85D3%2D4D34%2D828B%2DE5B1B428EA5E%7D]
[BRS_FRS_PS_ACC_Workpads_Manual_Write_Off_and_Incomming_Paument_v5.0|http://portal.mycompany.local/mycompany/someproject/_layouts/15/start.aspx#/someproject/Forms/AllItems.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2Fsomeproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS&View=%7B9A71C976%2D85D3%2D4D34%2D828B%2DE5B1B428EA5E%7D]
*Sign Offs:*
[BRS_FRS_PS_ACC_Payments_v20.0|http://portal.mycompany.local/mycompany/someproject/_layouts/15/start.aspx#/someproject/Forms/AllItems.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2Fsomeproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS%2FSign%2Doffs%2FPayments%2FV20%2E0&FolderCTID=0x0120005C60D5FB65C2C84191CB5ACDFD820AA6&View=%7B9A71C976%2D85D3%2D4D34%2D828B%2DE5B1B428EA5E%7D]
[BRS_FRS_PS_ACC_Workpads_Manual_Write_Off_and_Incomming_Paument_v5.0|http://portal.mycompany.local/mycompany/someproject/_layouts/15/start.aspx#/someproject/Forms/AllItems.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2Fsomeproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS%2FSign%2Doffs%2FWorkpads%20%26%20incoming%20payments%2FV5%2E0&FolderCTID=0x0120005C60D5FB65C2C84191CB5ACDFD820AA6&View=%7B9A71C976%2D85D3%2D4D34%2D828B%2DE5B1B428EA5E%7D]
*Technical Documentation:*
N/A
*Unit Testing:*
[TU_dd-1821|http://portal.mycompany.local/mycompany/someproject/SitePages/Home.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2Fsomeproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FUnit%20Testing&FolderCTID=0x0120005C60D5FB65C2C84191CB5ACDFD820AA6&View=%7B5AF02A9E%2D451A%2D443D%2DB8CA%2DAF7C7ED6F00C%7D]
this is how i pulled in the issue from Jira( my plan is to scan through all issues and update.
from jira import JIRA
import re
jira = JIRA(server=('https://mycompanydev.atlassian.net'),basic_auth=('user', 'password'))
issue = jira.issue("S1-3000")
print("Ticket nr: ", issue)
olddescription = issue.fields.description
newdescription = olddescription
So i managed to change the first part of the url with this line:
newdescription = newdescription.replace("http://portal.mycompany.local/mycompany/someproject/_layouts/15/start.aspx#/someproject/Forms/AllItems.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2F", "https://somecompany.sharepoint.com/sites/CCPortal/")
and this line:
newdescription = newdescription.replace("http://portal.mycompany.local/mycompany/someproject/SitePages/Home.aspx?RootFolder=%2Fmycompany%2Fsomeproject%2F", "https://mycompany.sharepoint.com/sites/CCPortal/")
this code completes successfully and changes the URL as intended.
Now i need to remove the end of the url from the string "View=" and the string "FolderCTID="
my line of code to do this:
newdescription = newdescription.replace(newdescription[newdescription.find("View=")-1:newdescription.find("]")],"")
and:
newdescription = newdescription.replace(newdescription[newdescription.find("FolderCTID="):newdescription.find("]")], "")
for some reason it only does the first 2 URLs:
result looks like this:
Good day
we need a new validation on the External Reference when doing work pads or amending manually when we do refund, it seems that the user that updates this is using Tab or Enter and therefore the payment files fails ,
we need users to be validated while updating refund reference same way as we limited claims payments for updating invoice numbers
thank you
regards
*BRS & FRS:*
[BRS_FRS_PS_ACC_Payments_v20.0|https://mycompany.sharepoint.com/sites/mycompany/someproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS]
[BRS_FRS_PS_ACC_Workpads_Manual_Write_Off_and_Incomming_Paument_v5.0|https://mycompany.sharepoint.com/sites/mycompany/someproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS]
*Sign Offs:*
[BRS_FRS_PS_ACC_Payments_v20.0|https://mycompany.sharepoint.com/sites/mycompany/someproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS%2FSign%2Doffs%2FPayments%2FV20%2E0&FolderCTID=0x0120005C60D5FB65C2C84191CB5ACDFD820AA6]
[BRS_FRS_PS_ACC_Workpads_Manual_Write_Off_and_Incomming_Paument_v5.0|https://mycompany.sharepoint.com/sites/mycompany/someproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FBRS%20%26%20FRS%2FSign%2Doffs%2FWorkpads%20%26%20incoming%20payments%2FV5%2E0&FolderCTID=0x0120005C60D5FB65C2C84191CB5ACDFD820AA6]
*Technical Documentation:*
N/A
*Unit Testing:*
[TU_MV-1821|https://mycompany.sharepoint.com/sites/mycompany/someproject%2F06%20Solution%20Documentation%2F03%20Accounting%2C%20Etc%2F07%20TIA%2FUnit%20Testing&FolderCTID=0x0120005C60D5FB65C2C84191CB5ACDFD820AA6&View=%7B5AF02A9E%2D451A%2D443D%2DB8CA%2DAF7C7ED6F00C%7D]
as you can see the code removed the first 2 "View=" strings with the trailing string to the end.
I cant figure out where I went wrong I also tried putting this in a while loop and just repeating the code 5 times for a test.
str.find returns the lowest index where the substring is found. So if newdescription has more than one "]", presumably because it contains more than one link, that means the returned index will only be correct for the first link.
str.find also accepts an optional start/end index to limit the search, so you can use the index of "View=" as an offset for the search for "]":
offset = newdescription.find("View=")
replace_me = newdescription[offset:newdescription.find("]", offset)]
newdescription = newdescription.replace(replace_me, "")
I am trying to get the contents of a list on I a board I created to understand some things about my work flow.
The API seems quite complex, and I have been at it for hours. I have an API key, as well as a Secret key.
I tried the following from their docs: https://api.trello.com/1/lists/4eea4ffc91e31d174600004a/cards?key=[application_key]&token=[optional_auth_token]
However, I am not sure where these letters/numbers are coming from: 4eea4ffc91e31d174600004a.
I read the following page: https://developers.trello.com/apis (which gave me the link to the url above), but there is no info on how to get 4eea4ffc91e31d174600004a.
I simply want to visit a url that gives me json or something of that vein, with all the contents of a list (e.g. the cards + their names). Then I can visit that link programmatically and do my analysis.
Edit: Using the trello developer sandbox: https://developers.trello.com/sandbox/ I found the id of a list, which I substituted into 4eea4ffc91e31d174600004a, but now I get the following: Taco says “invalid token”, but what does he know? He's just a dog.
I used the Secret key as the token, but I guess that's not the token. So the question boils down to how can I get a token?
Thanks
So the full answer is:
To get the cards in a list, three things are required:
API Key
List ID
Token
(Secret key isn't needed anywhere)
To get the List ID, the simplest way to do that is to use the developer sandbox https://developers.trello.com/sandbox/ then hit 'get lists' + 'execute' and obtain the id of the list of interest.
Note if you have multiple boards, you will need to specify the board id here: Trello.get('/boards/[board_id]/lists', success, error);. You can get the board id by hitting 'get boards' + 'execute', then looking for the id of interest.
To get a token, you need to go here: https://trello.com/1/connect?key=[application_key]&name=MyApp&response_type=token
Then you can make the call:
https://api.trello.com/1/lists/[list_id]/cards?key=[application_key]&token=[optional_auth_token]
I recently worked on Trello data using its RESTful API and using Python's py-trello. As the question is about accessing Trello list and its cards, will limit my solution to list access using Trello RESTful API and py-trello.
1. Using Trello RESTful API:
Following you need to form your URI to access the desired list and its cards JSON
i) API Key: You can get the key from https://trello.com/app-key
ii) Token: On the above page itself, you'll find link to the Token generation. Posting the snap shot below for convenience-
iii) list id: you can find this in the board JSON
Using these 3 items, below is how the RESTful URI to access a list is going to look like:
list_json_url = "https://api.trello.com/1/lists/replace_this_with_ur_list_id?cards=all&key=replace_this_with_ur_api_key&token=replace_this_with_your_token
Below is how i'm loading above list JSON in my Python program :
with urllib.request.urlopen(list_json_url) as fj:
data = json.load(fj)
2. Using py-trello:
There can be better ways to do this using py-trello's filtering features, i have just taken this from my entire multi-boards analysis code and added a condition to match a list id:
from trello import TrelloClient
API_KEY = "XXXXXXX"
API_TOKEN = "XXXXXXXXXX"
client = TrelloClient(api_key=API_KEY, token=API_TOKEN)
for board in client.list_boards():
for l in board.list_lists():
if l.id = "ur_list_id":
#do your list analysis here
That is the list id which you can get by an API call to the boards
You'll find details here.
https://developers.trello.com/apis#boards
Go to link: https://trello.com/app-key
Click in TOKEN
Click in Allow
Copy your token
DONE
I'm trying to change a username using the Admin SDK. I'm trying the following code to update this, using a dict object to store the new info, and using patch to update:
userinfo['primaryEmail'] = D['new_user'] + '#' + D['domain']
appsservice.users().patch(userKey = userEmail, body=userinfo)
It doesn't seem to be working, when I look at the admin console. The original username remains unchanged. I'm just wondering if I'm using the correct method. Should I be updating a different variable than primaryEmail or without using the domain affiliation? Seems like I'm just missing something rather obvious.
Thanks,
Tom
Add:
.execute()
To the end of the 2nd line to actually execute the api operation.