I'm trying to access to all events of my calendar, hosted on Nextcloud, with python and the caldav library.
With this code:
client = caldav.DAVClient(url) #like "https://..../nextcloud/remote.php/dav/calendars
principal = client.principal()
calendars = principal.calendars()
I can access to all my calendars and iterate over it.
How I can read only a specific calendar, with the name "calendar_name"? In this case I get all calendars, even if I specify the calendar name:
client = caldav.DAVClient(url) #like "https://..../nextcloud/remote.php/dav/calendars/user/calendar_name
principal = client.principal()
calendars = principal.calendars()
If I change the last line of code with calendar_name, I get an empty array.
calendar = principal.calendar('calendar_name')
Note: I can access all calendars and events with the first code posted, but all names are "None", even if the Url is right.
The second snippet still gives you all calendars because you first grab the account (.principal()) and then you list all calendars the account has (principal.calendars()).
The third snippet probably doesn't work because the name (the display name property, not the URL path component) of the calendar quite likely isn't calendar_name but something like Calendar. Theoretically it may even be empty.
To access a single calendar using its URL this may work, didn't try:
client = caldav.DAVClient(url)
calendar = caldav.Calendar(client=client,
url="/nextcloud/remote.php/dav/calendars/user/calendar_name")
Though it may be better to do something like this for various reasons:
client = caldav.DAVClient(url)
principal = client.principal()
calendars = principal.calendars()
calendar = any(c for c in calendars if c.url == your url)
To address your actual question, you need to add more information. If you want the (relative or absolute) URL of the calendar, use something like this:
print calendar.url
If you want to explicitly retrieve the calendar display name, this may work:
print calendar.get_properties([dav.DisplayName()])
Hope this helps.
Related
This is the code I've been using. It works when I want to create an appointment, but only in my main calendar. Do any of you know how to create the appointments in a secondary calendar?
import win32com.client
from win32com.client import Dispatch
outlook = win32com.client.Dispatch("Outlook.Application")
def sendMeeting():
appt = outlook.CreateItem(1) # AppointmentItem
appt.Start = "2021-5-28 16:10" # yyyy-MM-dd hh:mm
appt.Subject = "Fake meeting"
appt.Duration = 30 # In minutes (60 Minutes)
appt.Location = "The bat cave"
appt.Save()
appt.Send()
Do you mean a secondary Exchange account in the profile? Or a delegate Exchange mailbox?
In the former case, open the store from the Namespace.Stores collection, open the Calendar folder using Store.GetDefaulFolder(olFolderCalendar), create new item using MAPIFolder.Items.Add. In the latter case, you can use Namespace.GetSharedDefaultFolder(Recipient, olFolderCalendar) (where Recipient can be retrieved from Namespace.CreateRecipient).
If it is a subfolder in your primary store, you can access it from its parent folder and call MAPIFolder.Items.Add. E.g. if it is a subfolder of your default Calendar folder, use outlook.Session.GetDefaultFolder(olFolderCalendar).Folders.Item("The name"). If it is on the same level as your Calendar folder, use outlook.Session.GetDefaultFolder(olFolderCalendar).Parent.Folders.Item("The name").
Trying to use the Bing Ads API to duplicate what I see on the Hourly report.
Unfortunately, even though I'm properly authenticated, the data I'm getting back is only for One Campaign (one which has like 1 impression per day). I can see the data in the UI just fine, but authenticated as the same user via the API, I can only seem to get back the smaller data set. I'm using https://github.com/BingAds/BingAds-Python-SDK and basing my code on the example:
def get_hourly_report(
account_id,
report_file_format,
return_only_complete_data,
time):
report_request = reporting_service.factory.create('CampaignPerformanceReportRequest')
report_request.Aggregation = 'Hourly'
report_request.Format = report_file_format
report_request.ReturnOnlyCompleteData = return_only_complete_data
report_request.Time = time
report_request.ReportName = "Hourly Bing Report"
scope = reporting_service.factory.create('AccountThroughCampaignReportScope')
scope.AccountIds = {'long': [account_id]}
# scope.Campaigns = reporting_service.factory.create('ArrayOfCampaignReportScope');
# scope.Campaigns.CampaignReportScope.append();
report_request.Scope = scope
report_columns = reporting_service.factory.create('ArrayOfCampaignPerformanceReportColumn')
report_columns.CampaignPerformanceReportColumn.append([
'TimePeriod',
'CampaignId',
'CampaignName',
'DeviceType',
'Network',
'Impressions',
'Clicks',
'Spend'
])
report_request.Columns = report_columns
return report_request
I'm not super familiar with these ad data APIs, so any insight will be helpful, even if you don't have a solution.
I spent weeks back and forth with Microsoft Support. Here's the result:
You can get logs out of the examples by adding this code:
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
The issue was related to the way the example is built. In the auth_helper.py file there is a method named authenticate that looks like this:
def authenticate(authorization_data):
# import logging
# logging.basicConfig(level=logging.INFO)
# logging.getLogger('suds.client').setLevel(logging.DEBUG)
# logging.getLogger('suds.transport.http').setLevel(logging.DEBUG)
customer_service = ServiceClient(
service='CustomerManagementService',
version=13,
authorization_data=authorization_data,
environment=ENVIRONMENT,
)
# You should authenticate for Bing Ads services with a Microsoft Account.
authenticate_with_oauth(authorization_data)
# Set to an empty user identifier to get the current authenticated Bing Ads user,
# and then search for all accounts the user can access.
user = get_user_response = customer_service.GetUser(
UserId=None
).User
accounts = search_accounts_by_user_id(customer_service, user.Id)
# For this example we'll use the first account.
authorization_data.account_id = accounts['AdvertiserAccount'][0].Id
authorization_data.customer_id = accounts['AdvertiserAccount'][0].ParentCustomerId
As you can see, at the very bottom, it says "For this example, we'll use the first account." It turns out that my company had 2 accounts. This was not configurable anywhere and I had no idea this code was here, but you can add a breakpoint here to see your full list of accounts. We only had 2, so I flipped the 0 to a 1 and everything started working.
I need your help to order listed item.
I am trying to make apps that can send message to his/her friends ( just like social feeds ). After watching Bret Slatkin talk about create microblogging here's my code:
class Message(ndb.Model):
content = ndb.TextProperty()
created = ndb.DateTimeProperty(auto_now=True)
class MessageIndex(ndb.Model):
receivers = ndb.StringProperty(repeated=True)
class BlogPage(Handler):
def get(self):
if self.request.cookies.get("name"):
user_loggedin = self.request.cookies.get("name")
else:
user_loggedin = None
receive = MessageIndex.query(MessageIndex.receivers == user_loggedin)
receive = receive.fetch()
message_key = [int(r.key.parent().id()) for r in receive]
messages = [Message.get_by_id(int(m)) for m in message_key]
for message in messages:
self.write(message)
The first I do a query to get all message that has my name in the receivers. MessageIndex is child of Message, then I can get key of all message that I receive. And the last is I iter get_by_id using list of message key that I get.
This works fine, but I want to filter each message by its created datetime and thats the problem. The final output is listed item, which cant be ordered using .order or .filter
Maybe some of you can light me up.
You can use the message keys in an 'IN' clause in the Message query. Note that you will need to use the parent() key value, not the id() in this case.
eg:
# dtStart, dtEnd are datetime values
message_keys = [r.key.parent() for r in receive]
query = Message.query(Message._key.IN(message_keys), Message.created>dtStart, Message.created<dtEnd)
query = query.order(Message.created) # or -Message.created for desc
messages = query.fetch()
I am unsure if you wish to simply order by the Message created date, or whether you wish to filter using the date. Both options are catered for above.
If you delete an user or group in windows AD, it will in "DElETE objects".
I want to use python ldap lib to get them.
Code:
<code>
import ldap
uri = "ldap://10.64.74.17"
user = "XXXXXXXXXX"
password = "XXXXXXXXXXXX"
ldap.set_option(ldap.OPT_REFERRALS, 0)
ldap.set_option(ldap.OPT_NETWORK_TIMEOUT, 5)
ldap.protocol_version = 3
ldapClient = ldap.initialize(uri)
ldapClient.simple_bind_s(user, password)
filter = "(&(objectclass=person)(isDeleted=true)(!(objectclass=computer)))"
results = ldapClient.search_s("DC=xx,DC=com", ldap.SCOPE_SUBTREE,filter)
for result in results:
print result
ldapClient.unbind_s()
</code>
It can't show deleted objects.
What's wrong with this code?
You need to add an ldap control to your search : create the request control for the particular operation, and then pass a collection of controls to your search request as an optional parameter.
In your case, this OID for AD is 1.2.840.113556.1.4.417.
LDAP_SERVER_SHOW_DELETED_OID : 1.2.840.113556.1.4.417
Used with an LDAP operation to specify that tombstones and deleted-objects are visible to the operation.
tombstone_control = ('1.2.840.113556.1.4.417',criticality=1)
results = ldapClient.search_s("DC=xx,DC=com", ldap.SCOPE_SUBTREE,filter, [tombstone_control])
You can also scope your search base to CN=Deleted Objects, DC=xx,DC=com as this is where all deleted objects end up. You should make sure your deleted objects are there first. You can use ldp.exe to check.
I have a problem with google calendar api.
How can you select which calendar to add an event? It add always to default calendar?
thanks
You can list the calendars using the GetOwnCalendarsFeed() and GetAllCalendarsFeed() calls. This will return a list of entries, each of which holds attributes for a given calendar. You need to obtain the calendar's url from the entry.content.src attribute, and use this on your InsertEntry call:
client = calendar.service.CalendarService(email='x', password='y')
feed = client.GetOwnCalendarsFeed()
# map the 'title' -> 'url'
urls = dict((e.title.text, e.content.src) for e in feed.entry)
client.InsertEvent(event, urls['My Calendar'])