How can I make a text search in a specific channel\chat?
In the app & web client you can search with a text and date range,
and you will get list of results + counter.
Is there a method I can invoke?
This is probably what you want introduced in layer 12.
messages.messages#8c718e87 messages:Vector<Message> chats:Vector<Chat> users:Vector<User> = messages.Messages;
messages.messagesSlice#b446ae3 count:int messages:Vector<Message> chats:Vector<Chat> users:Vector<User> = messages.Messages;
---functions---
messages.search#7e9f2ab peer:InputPeer q:string filter:MessagesFilter min_date:int max_date:int offset:int max_id:int limit:int = messages.Messages;
Related
I'm using Firebase Firestore in my Python project (with their official Python SDK) and having trouble performing count() aggregation. This funciton is supported according to their docs. However, they do not provide Python example ( they do in other parts of documentation ). I tried to play with it in Python console, tried something like this:
query = db.collection('videos').where('status', '==', 'pending')
query.count()
without any luck. So I'm wondering how is it possible to implement? Does Python SDK support this functionality?
Firebase Admin Python SDK doesn't support that query yet. You can still use the runAggregationQuery REST API meanwhile. The Google Cloud Firestore Python SDK has Aggregation result types available from v2.7.0+ so it should be available in Admin SDK soon.
Although the API for this purpose is not fully ready but it's coming along. If you don't wanna use the REST API as suggested by #Dharmaraj, you can do something like this for now:
from google.cloud.firestore_v1.services.firestore import FirestoreClient
from google.cloud.firestore_v1.types.document import Value
from google.cloud.firestore_v1.types.firestore import RunAggregationQueryRequest
from google.cloud.firestore_v1.types.query import (
StructuredAggregationQuery,
StructuredQuery,
)
Aggregation = StructuredAggregationQuery.Aggregation
CollectionSelector = StructuredQuery.CollectionSelector
Count = Aggregation.Count
FieldFilter = StructuredQuery.FieldFilter
FieldReference = StructuredQuery.FieldReference
Filter = StructuredQuery.Filter
Operator = StructuredQuery.FieldFilter.Operator
client = FirestoreClient()
project_id = ""
request = RunAggregationQueryRequest(
parent=f"projects/{project_id}/databases/(default)/documents",
structured_aggregation_query=StructuredAggregationQuery(
structured_query=StructuredQuery(
from_=[CollectionSelector(collection_id="videos")],
where=Filter(
field_filter=FieldFilter(
field=FieldReference(
field_path="status",
),
op=Operator.EQUAL,
value=Value(string_value="pending"),
)
),
),
aggregations=[Aggregation(count=Count())],
),
)
stream = client.run_aggregation_query(request=request)
print(next(stream).result.aggregate_fields["field_1"].integer_value)
Output:
1
Generally the following would work to count the total number of documents in a collection:
def count_documents(collection_id: str) -> int:
client = FirestoreClient()
project_id = ""
request = RunAggregationQueryRequest(
parent=f"projects/{project_id}/databases/(default)/documents",
structured_aggregation_query=StructuredAggregationQuery(
structured_query=StructuredQuery(
from_=[CollectionSelector(collection_id=collection_id)]
),
aggregations=[Aggregation(count=Count())],
),
)
stream = client.run_aggregation_query(request=request)
return next(stream).result.aggregate_fields["field_1"].integer_value
print(count_documents(collection_id="videos"))
Output:
10
Make sure that you have google-cloud-firestore>=2.7.3 and also remember to set the value of project_id variable in the count_documents function accordingly.
Is there a way to get the URL or/and text of a button below the message?
I'm using telethon with python.
You can access the buttons of a message using its message.buttons property.
This property returns a list, each element of list is a row(list) of MessageButton.
For example, if you want to access the URL or text of send music to friends button which is in row 1 and column 0 (0 based index), you can use the following code:
peer_username = "Telegram identifier"
message = client.get_messages(peer_username)[0]
message_button = message.buttons[1][0]
text = message_button.text
url = message_button.url
Sometimes the url property in the MessageButton is empty, and you can use its button property to access the KeyboardButton. For example:
url = message_button.button.url
I am trying to get a list of workset name and id's from the active document using Revit API inside of Python node in Dynamo. I am trying to access workset table but this code returns nothing:
doc = __doc__
workset = ActiveWorkset(doc)
active_id = workset.ActiveWorksetId()
OUT = active_id
For now I was just trying to see if i can get active workset first but even that doesnt work.
I haven't tried this in Dynamo, but my trusty RevitPythonShell thinks this should work:
worksetTable = doc.GetWorksetTable()
activeId = worksetTable.GetActiveWorksetId()
workset = worksetTable.GetWorkset(activeId)
this is based on the example from the Revit 2014 API document in the SDK...
The output:
>>> workset
<Autodesk.Revit.DB.Workset object at 0x000000000000002E [Autodesk.Revit.DB.Workset]>
Based on your example, you probably want to do this at the end:
OUT = activeId
I am trying to implement this into python, but I am having difficulty:
https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
here is what I have:
def reqs():
t = Twitter(auth=OAuth('...'))
tweets = t.statuses.user_timeline.snl()
retweetids = t.statuses.retweeted_by(id=str(tweets[0]['id'])) <<does not work.
print retweetids
use
retweets
instead of retweeters
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'])