# Python \> Get post content if mentioned

**URL:** <https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309>\
**Category:** Development\
**Tags:** mentions\
**Created:** [December 8, 2022, 6:49pm UTC](https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309 "2022-12-08T18:49:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [December 8, 2022, 10:24pm UTC](https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309/2 "2022-12-08T22:24:46Z")

</div>

Thanks for posting the link to fluent-discourse!

> [@MarcP](#):
>
> am trying to simply receive the posts if @UserA gets mentioned somewhere.

I’m currently trying to get up to speed with Python, so it’s possible there are better ways of approaching this than what I’m outlining here.

`mention = client.notifications.json.get()`

This is returning a [dictionary](https://docs.python.org/3/library/stdtypes.html#dict) of mentions for the `username` you set when you created the `client`. I am assuming that you set the `username` to `UserA` when you created the `client`.

To confirm that a dictionary is being returned, you can run:

```python
print(type(mention))

```

That should return `<class 'dict'>`

You can see the dictionary’s keys by running:

```python
print(list(mention))

```

That will return `['notifications', 'total_rows_notifications', 'seen_notification_id', 'load_more_notifications']`

For your case, you want the values that are found under the `notifications` key:

```python
notifications = mention['notifications']

```

If you then run `type(notifications)`, you’ll see that it is a [list](https://docs.python.org/3/library/stdtypes.html#lists). To get notifications that were triggered by mentions of `UserA`, you need to iterate through the list to find entries where the `notification_type` is set to `1`. The easiest way to see the values for the Discourse notification types is to run `Notification.types` from your Discourse site’s rails console:

```ruby
 pry(main)> Notification.types
=> {:mentioned=>1,
 :replied=>2,
 :quoted=>3,
 :edited=>4,
 :liked=>5,
 ...

```

So to get “mention” notifications for the user whose username you’ve set for the `client`, try something like this (I’m testing this in the Python interpreter as I type it):

```python
data = client.notifications.json.get()
notifications = data['notifications']
# Create an empty list object to store "mention" notifications
mentions = []
# Iterate through the `notifications` list to find all entries where the `notification_type` is set to `1`
for notification in notifications:
    if notification['notification_type'] == 1:
        mentions.append(notification)

```

That will create a list of notifications that were triggered by mentions. Each item in the list will be a dictionary. You can check it with something like:

```python
for mention in mentions:
    print(mention['topic_id'], mention['post_number'])    

```

---

_[View the full topic](https://meta.discourse.org/t/python-get-post-content-if-mentioned/248309)._
