Browse Source

Configuration and debug

ekardnam 4 years ago
parent
commit
6eead9e714
4 changed files with 44 additions and 26 deletions
  1. 5 5
      .env.dist
  2. 7 0
      message.template
  3. 20 20
      requirements.txt
  4. 12 1
      run.py

+ 5 - 5
.env.dist

@@ -1,7 +1,7 @@
 ACCESS_TOKEN=
-DAYS_SINCE=
-INSTANCE_BASE_URL=https://mastodon.bida.im
-INSTANCE_MAX_CHARS=840
-TOOT_TEMPLATE=
-DEBUG=
+DAYS_SINCE=1
+INSTANCE_BASE_URL=http://mastodon.local
+INSTANCE_MAX_CHARS=500
+TOOT_TEMPLATE=message.template
+DEBUG=False
 ACCOUNT_ID=

+ 7 - 0
message.template

@@ -0,0 +1,7 @@
+Welcome on this Mastodon instance @{{ username }}!
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+
+
+
+
+Welcome again!

+ 20 - 20
requirements.txt

@@ -1,20 +1,20 @@
-asn1crypto==0.24.0
-certifi==2018.8.24
-cffi==1.11.5
-chardet==3.0.4
-cryptography==2.3.1
-decorator==4.3.0
-environs==4.0.0
-http-ece==1.0.5
-idna==2.7
-Jinja2==2.10
-MarkupSafe==1.0
-marshmallow==2.15.4
-Mastodon.py==1.3.1
-pycparser==2.18
-python-dateutil==2.7.3
-python-dotenv==0.9.1
-pytz==2018.5
-requests==2.19.1
-six==1.11.0
-urllib3==1.23
+asn1crypto
+certifi
+cffi
+chardet
+cryptography
+decorator
+environs
+http-ece
+idna
+Jinja2
+MarkupSafe
+marshmallow
+Mastodon.py
+pycparser
+python-dateutil
+python-dotenv
+pytz
+requests
+six
+urllib3

+ 12 - 1
run.py

@@ -34,6 +34,11 @@ class Bot(object):
         self.until = self.until.replace(hour=23, minute=59, second=59)
 
     def _should_get_msg(self, account):
+        if self.debug_mode:
+            print("Filtering {}".format(account.username))
+            print("Created at: {}".format(account.created_at))
+            print("self.since_at is {}".format(self.since_at))
+            print("self.until is {}".format(self.until))
         return account.url.startswith(self.instance_url) and account.created_at >= self.since_at and account.created_at <= self.until and not account.locked
 
     def get_users(self):
@@ -41,6 +46,7 @@ class Bot(object):
 
         def get_prev(users):
             followers = self.client.fetch_previous(users)
+
             filtered = [follower for follower in followers if self._should_get_msg(follower)]
             users_to_msg.extend(filtered)
 
@@ -101,7 +107,7 @@ class Bot(object):
 
         self.log.info('{} toots sent!'. format(len(users_to_msg)))
 
-def run():
+def create_bot():
     env = Env()
     env.read_env()
     access_token = env('ACCESS_TOKEN')
@@ -123,6 +129,11 @@ def run():
               account_id=account_id,
               max_chars=max_chars)
 
+    return bot
+
+def run():
+    bot = create_bot()
+
     while True:
         bot.go()
         time.sleep(2*60) # 2 mins