2016-04-01 10 views
0

Diese Frage bezieht sich auf die Tweepy-Bibliothek.Wie bekomme ich den Text von einer direkten Nachricht?

Ich benutze den Befehl (unten), um die letzte direkte Nachricht zu erhalten. Ich möchte die user_id und den Text der Nachricht erhalten und zurück antworten. Allerdings kann ich nicht verstehen, wie man den Text extrahiert. Irgendeine Hilfe?

api.direct_messages(count=1) 

Auf die Nachricht einfach drucken, ist es das, was es gibt:

[DirectMessage(sender=User(statuses_count=8452, verified=False, _json={'default_profile_image': False, 'statuses_count': 8452, 'following': True, 'verified': False, 'entities': {'description': {'urls': []}}, 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/7904887943048/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg', 'screen_name': 'xxxtnb', 'is_translation_enabled': False, 'id': 448743511, 'id_str': '448473511', 'notifications': False, 'name': 'Xxx Xxx', 'profile_text_color': '1C1F23', 'profile_background_tile': True, 'location': 'xxxx', 'default_profile': False, 'profile_use_background_image': True, 'profile_sidebar_fill_color': 'C9C9C9', 'lang': 'en', 'protected': False, 'has_extended_profile': False, 'profile_background_color': '07090B', 'is_translator': False, 'created_at': 'Fri Jun 05 11:39:26 +0000 2009', 'contributors_enabled': False, 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/3788000004442443400505954094/26ac579d33b26ee9e6748a3563fe3754dc_normal.png', 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/44873556411/135934873965', 'time_zone': 'xxxx', 'description': '|DSECRIPTION|', 'listed_count': 2, 'profile_sidebar_border_color': 'FFFFFF', 'followers_count': 296, 'favourites_count': 19, 'geo_enabled': False, 'friends_count': 2332, 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/79048873328/ab960e433a9bfeb7dd71c91e5b4f5c9dd1.jpeg', 'follow_request_sent': False, 'utc_offset': 25200, 'profile_image_url': 'http://pbs.twimg.com/profile_images/378800000324505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', 'url': None, 'profile_link_color': 'C34242'}, id=44843473511, screen_name='xxxtnb', profile_background_image_url='http://pbs.twimg.com/profile_background_images/7904884343728/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg', profile_link_color='C34242', id_str='44873543411', listed_count=2, notifications=False, following=True, _api=<tweepy.api.API object at 0x000000000327D828>, geo_enabled=False, location='LOCATION', default_profile=False, profile_use_background_image=True, favourites_count=19, profile_sidebar_fill_color='C9C9C9', lang='en', utc_offset=25200, friends_count=232, protected=False, has_extended_profile=False, profile_background_color='07090B', followers_count=2926, created_at=datetime.datetime(20309, 6, 5,3 11, 39, 26), contributors_enabled=False, profile_image_url_https='https://pbs.twimg.com/profile_images/3788003234000505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', profile_banner_url='https://pbs.twimg.com/profile_banners/44873511/1359873943465', profile_background_tile=True, description='|DSECRIPTION|', profile_text_color='1C1F23', profile_sidebar_border_color='FFFFFF', is_translator=False, entities={'description': {'urls': []}}, is_translation_enabled=False, time_zone=,profile_background_image_url_https='https://pbs.twimg.com/profile_background_images/790488728/ab960e4a9bfeb7dd71c43491e5b4f5c9dd1.jpeg', follow_request_sent=False, name='Xxx Xxx', profile_image_url='http://pbs.twimg.com/profile_images/3788000563400505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', url=None, default_profile_image=False), sender_screen_name='xxxtnb', sender_id=4487345511, sender_id_str='4487343511', text='kjbkljb', id=715904763565666629443, created_at=datetime.datetime(2016, 4, 1, 14, 12, 51), id_str='715904763565629443', recipient=User(statuses_count=8, verified=False, _json={'default_profile_image': False, 'statuses_count': 8, 'following': False, 'verified': False, 'entities': {'description': {'urls': []}}, 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/2424565639181/KOJ.jpg', 'screen_name': 'xxxx', 'is_translation_enabled': False, 'id': 82332348693, 'id_str': '82232348693', 'notifications': False, 'name': 'Yyyyy yyyyy', 'profile_text_color': '0C3E53', 'profile_background_tile': False, 'location': xxxx', 'default_profile': False, 'profile_use_background_image': True, 'profile_sidebar_fill_color': 'FFF7CC', 'lang': 'en', 'protected': False, 'has_extended_profile': False, 'profile_background_color': 'BADxFCD', 'is_translator': False, 'created_at': xxx 2009', 'contributors_enabled': False, 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1302134054090532/36114_1220026641036_1840037693_409509_786157_n_normal.jpg', 'time_zone':, 'description': DESC.', 'listed_count': 0, 'profile_sidebar_border_color': 'F2E195', 'followers_count': 134, 'favourites_count': 0, 'geo_enabled': False, 'friends_count': 49, 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/242439134381/KOJ.jpg', 'follow_request_sent': False, 'utc_offset': 19800, 'profile_image_url': 'http://pbs.twimg.com/profile_images/1302134032/36114_1220026641036_341840037693_409509_786157_n_normal.jpg', 'url': None, 'profile_link_color': 'FF0000'}, id=8234834693, screen_name='', profile_background_image_url='http://pbs.twimg.com/profile_background_images/2424343439181/KOJ.jpg', profile_link_color='FF0000', id_str='82348693', listed_count=0, notifications=False, following=False, _api=<tweepy.api.API object at 0x000000000327D828>, geo_enabled=False, location=’x', default_profile=False, profile_use_background_image=True, favourites_count=0, profile_sidebar_fill_color='FFF7CC', lang='en', utc_offset=194800, friends_count=494, protected=False, has_extended_profile=False, profile_background_color='BADFCD', followers_count=144, created_at=datetime.datetime(2009, 10, 14, 12, 36, 46), contributors_enabled=False, profile_image_url_https='https://pbs.twimg.com/profile_images/130213404332/4336114_1220026641036_1840037693_40943509_786157_n_normal.jpg', profile_background_tile=False, description=DESC.', profile_text_color='0C3E53', profile_sidebar_border_color='F2E195', is_translator=False, entities={'description': {'urls': []}}, is_translation_enabled=False, time_zone='’, profile_background_image_url_https='https://pbs.twimg.com/profile_background_images/242434434349181/KOJ.jpg', follow_request_sent=False, name='Yyyyy yyyyy', profile_image_url='http://pbs.twimg.com/profile_images/1302134032/36143414_1220026641036_1840037693_40954309_786157_n_normal.jpg', url=None, default_profile_image=False), recipient_id=8234348693, entities={'user_mentions': [], 'hashtags': [], 'urls': [], 'symbols': []}, 

Ich möchte den Inhalt der Nachricht von dieser gesendet bekommen, unter dem Text-Tag.

+0

Weitere Kontext - Bibliothek verwendet, mehr Zeilen des Beispielcodes nützlich wären –

+0

@YuriSchimke Die Bibliothek in dem Tags markiert worden ist, war es tweepy. Was den Kontext angeht, gibt es nicht wirklich viel, weil meine Frage so einfach ist, wie ich einen Wert ausdrucke, aber für Ihre Klarstellung habe ich auch die Ausgabe gezeigt, die ich vom Befehl bekomme und was ich stattdessen möchte. – CoderBC

Antwort

0

Das funktioniert für mich.

api.direct_messages(count=1)[0].text 
Verwandte Themen