Skip to content

Commit 7890834

Browse files
author
Soheil Behnezhad
committed
Implement testing mode for different data types
1 parent 79380c8 commit 7890834

5 files changed

+225
-105
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ readable and contributable.
55

66
## Know Him Better
77
- Twizhoosh does not talk too much and will not bother people who follow him.
8-
- He does not reply to a tweet more than once.
9-
- He never replies to people he is not following.
108
- He does not have any long term memory.
119
- He would not be rude to anyone, unless it is necessary.
1210
- He is smart.

core/utils/sample_tweet.py

-99
This file was deleted.
+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
sample_tweet = {
2+
"coordinates": None,
3+
"favorited": False,
4+
"truncated": False,
5+
"favorite_count": 10,
6+
"created_at": "Wed Aug 29 17:12:58 +0000 2012",
7+
"id_str": "240859602684612608",
8+
"entities": {
9+
"urls": [
10+
{
11+
"expanded_url": "https://dev.twitter.com/blog/twitter-certified-products",
12+
"url": "https://t.co/MjJ8xAnT",
13+
"indices": [
14+
52,
15+
73
16+
],
17+
"display_url": "dev.twitter.com/blog/twitter-c\u2026"
18+
}
19+
],
20+
"hashtags": [
21+
22+
],
23+
"user_mentions": [
24+
25+
]
26+
},
27+
"in_reply_to_user_id_str": None,
28+
"contributors": None,
29+
"text": "Introducing the Twitter Certified Products Program: https://t.co/MjJ8xAnT",
30+
"retweet_count": 121,
31+
"in_reply_to_status_id_str": None,
32+
"id": 240859602684612608,
33+
"geo": None,
34+
"retweeted": False,
35+
"possibly_sensitive": False,
36+
"in_reply_to_user_id": None,
37+
"place": None,
38+
"user": {
39+
"profile_sidebar_fill_color": "DDEEF6",
40+
"profile_sidebar_border_color": "C0DEED",
41+
"profile_background_tile": False,
42+
"name": "Twitter API",
43+
"profile_image_url": "http://a0.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_normal.png",
44+
"created_at": "Wed May 23 06:01:13 +0000 2007",
45+
"location": "San Francisco, CA",
46+
"follow_request_sent": False,
47+
"profile_link_color": "0084B4",
48+
"is_translator": False,
49+
"id_str": "6253282",
50+
"entities": {
51+
"url": {
52+
"urls": [
53+
{
54+
"expanded_url": None,
55+
"url": "http://dev.twitter.com",
56+
"indices": [
57+
0,
58+
22
59+
]
60+
}
61+
]
62+
},
63+
"description": {
64+
"urls": [
65+
66+
]
67+
}
68+
},
69+
"default_profile": True,
70+
"contributors_enabled": True,
71+
"favourites_count": 24,
72+
"url": "http://dev.twitter.com",
73+
"profile_image_url_https": "https://si0.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_normal.png",
74+
"utc_offset": -28800,
75+
"id": 6253282,
76+
"profile_use_background_image": True,
77+
"listed_count": 10775,
78+
"profile_text_color": "333333",
79+
"lang": "en",
80+
"followers_count": 1212864,
81+
"protected": False,
82+
"notifications": None,
83+
"profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png",
84+
"profile_background_color": "C0DEED",
85+
"verified": True,
86+
"geo_enabled": True,
87+
"time_zone": "Pacific Time (US & Canada)",
88+
"description": "The Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website.",
89+
"default_profile_image": False,
90+
"profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png",
91+
"statuses_count": 3333,
92+
"friends_count": 31,
93+
"following": None,
94+
"show_all_inline_media": False,
95+
"screen_name": "twitterapi"
96+
},
97+
"in_reply_to_screen_name": None,
98+
"source": "<a href='www.example.com'>YoruFukurou</a>",
99+
"in_reply_to_status_id": None,
100+
}
101+
102+
sample_direct_message = {
103+
'direct_message': {
104+
'recipient': {
105+
'profile_sidebar_fill_color': 'DDEEF6',
106+
'screen_name': 'twizhoosh',
107+
'default_profile_image': False,
108+
'id': 1000000000,
109+
'profile_use_background_image': True,
110+
'listed_count': 1,
111+
'description': 'ربات متن باز و باهوش فارسی زبان. :)',
112+
'geo_enabled': False,
113+
'favourites_count': 36,
114+
'profile_background_tile': False,
115+
'profile_background_color': 'C0DEED',
116+
'utc_offset': None,
117+
'notifications': False,
118+
'profile_link_color': '0084B4',
119+
'lang': 'en',
120+
'profile_background_image_url_https': 'https://abs.twimg.com/images/themes/theme1/bg.png',
121+
'verified': False, 'created_at': 'Tue Dec 23 12:30:05 +0000 2014',
122+
'profile_background_image_url': 'http://abs.twimg.com/images/themes/theme1/bg.png',
123+
'following': False,
124+
'profile_sidebar_border_color': 'C0DEED',
125+
'profile_image_url': 'http://pbs.twimg.com/profile_images/547545618726391809/TZWXD0l7_normal.jpeg',
126+
'location': 'Iran', 'url': 'https://github.com/Soben713/twizhoosh', 'contributors_enabled': False,
127+
'name': 'Twizhoosh',
128+
'profile_image_url_https': 'https://pbs.twimg.com/profile_images/547545618726391809/TZWXD0l7_normal.jpeg',
129+
'default_profile': True,
130+
'friends_count': 118,
131+
'protected': False,
132+
'time_zone': None,
133+
'follow_request_sent': False,
134+
'profile_location': None,
135+
'followers_count': 103,
136+
'profile_text_color': '333333',
137+
'is_translator': False,
138+
'statuses_count': 390,
139+
'id_str': '2938231733',
140+
'is_translation_enabled': False
141+
},
142+
'sender_id': 2000000000,
143+
'entities': {'user_mentions': [], 'symbols': [], 'hashtags': [], 'urls': []}, 'recipient_id_str': '2938231733',
144+
'sender_screen_name': 'FatemehTarashi',
145+
'sender': {
146+
'profile_sidebar_fill_color': '060B1A',
147+
'screen_name': 'X',
148+
'default_profile_image': False,
149+
'id': 2000000000,
150+
'profile_use_background_image': True,
151+
'listed_count': 2,
152+
'description': 'X',
153+
'geo_enabled': True,
154+
'favourites_count': 3106,
155+
'profile_background_tile': False,
156+
'profile_background_color': '030303',
157+
'utc_offset': 12600,
158+
'follow_request_sent': False,
159+
'notifications': False,
160+
'profile_link_color': '59665D',
161+
'lang': 'en',
162+
'profile_background_image_url_https': '',
163+
'verified': False,
164+
'created_at': 'Mon Aug 27 23:34:18 +0000 2012',
165+
'profile_background_image_url': '',
166+
'following': False,
167+
'profile_sidebar_border_color': 'FFFFFF',
168+
'profile_image_url': '',
169+
'location': 'Tehran ',
170+
'url': None,
171+
'contributors_enabled': False,
172+
'name': 'X',
173+
'profile_image_url_https': '',
174+
'default_profile': False,
175+
'friends_count': 56,
176+
'protected': True,
177+
'time_zone': 'Tehran',
178+
'profile_banner_url': 'https://pbs.twimg.com/profile_banners/785720312/1420565171',
179+
'profile_location': None,
180+
'followers_count': 59,
181+
'profile_text_color': '066066',
182+
'is_translator': False,
183+
'statuses_count': 3094,
184+
'id_str': '785720312',
185+
'is_translation_enabled': False
186+
},
187+
'recipient_id': 1000000000,
188+
'sender_id_str': '2000000000',
189+
'text': '',
190+
'created_at': 'Wed Jan 07 14:02:58 +0000 2015',
191+
'recipient_screen_name': 'twizhoosh',
192+
'id_str': '552827737174720515',
193+
'id': 552827737174720515
194+
}
195+
}

standalone_runner.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def run():
2222
for script in scripts:
2323
remaining_chunks[script.__class__.__name__] -= 1
2424
if remaining_chunks[script.__class__.__name__] == 0:
25-
log("Running standalone script: {0}".format(script.__class__.__name__))
2625
remaining_chunks[script.__class__.__name__] = script.repeat_time
2726
script.on_called()
2827

twitter_related_scripts_runner.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from twython import *
77
from twython.exceptions import TwythonError, TwythonRateLimitError
88

9-
from core.utils.singleton import Singleton
9+
from core.utils.sample_twitter_responses import sample_tweet, sample_direct_message
1010

11+
from core.utils.singleton import Singleton
1112
from core.utils.logging import log
1213
from core import settings, script_loader
1314

@@ -62,6 +63,11 @@ def load_scripts(self):
6263

6364
def on_success(self, data):
6465
data_type = ParseStreamingData.get_type_of_data(data)
66+
67+
if not data_type:
68+
log("Type of data unknown \n {0}".format(data))
69+
return
70+
6571
log("Data received, with type: " + data_type)
6672
log("Data: {0}".format(data))
6773
for script in self.scripts.setdefault(data_type, []):
@@ -86,11 +92,32 @@ def user(self, *args, **kwargs):
8692
log("Twython error {0}".format(e))
8793

8894

95+
class Testing(StreamingSingleton):
96+
def __init__(self, *args, **kwargs):
97+
self.load_scripts()
98+
99+
def user(self, *args, **kwargs):
100+
while True:
101+
input_type = input("Enter a data type number \n 1. Timeline \n 2. Direct Message \n 3. Custom data \n")
102+
if input_type == '1':
103+
timeline_text = input("Enter a tweet\n")
104+
data = sample_tweet
105+
data['text'] = timeline_text
106+
elif input_type == '2':
107+
message_text = input("Enter a direct message to @" + settings.TWIZHOOSH_USERNAME + "\n")
108+
data = sample_direct_message
109+
data['direct_message']['text'] = message_text
110+
else:
111+
data = eval(input("Enter your data object \n"))
112+
113+
self.on_success(data)
114+
115+
89116
def run():
90117
if not settings.DEBUG:
91118
log("Starting streamer...")
92119
stream = StreamingSingleton()
93120
stream.user(replies="all")
94121
else:
95-
# TODO: implement testing mode
96-
log("Twitter related scripts testing mode is not ready...")
122+
stream = Testing()
123+
stream.user(replies="all")

0 commit comments

Comments
 (0)