Skip to content

Commit 979bb31

Browse files
committed
access_token
1 parent 1232061 commit 979bb31

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

src/constants.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
from __future__ import unicode_literals
44

5-
VK_PUBLIC_WALL_URL = 'https://api.vk.com/method/wall.get?domain={0}&count=10&v=5.53&access_token=4a53b9544a53b9544a53b9546b4a310f4144a534a53b95410bfd115ea469a861df8c613'
6-
7-
VK_PRIVATE_WALL_URL = 'https://api.vk.com/method/wall.get?domain={0}&count=10&access_token={2}&v=5.53'
5+
VK_WALL_URL = 'https://api.vk.com/method/wall.get?domain={0}&count=10&access_token={1}&v=5.53'
86

97
VK_POST_URL = 'https://vk.com/{0}?w=wall{1}_{2}'
108

src/vk_fetcher.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
logger = logging.getLogger('vk_fetcher')
1111

1212

13-
def fetch(public_walls, private_walls, last_fetch_time, access_token):
13+
def fetch(public_walls, last_fetch_time, access_token):
1414
logger.debug('fetch(%s, %s)', public_walls, last_fetch_time)
1515

1616
posts = []
1717

1818
if public_walls is not None:
1919
for wall in public_walls:
20-
posts.extend(_get_wall_posts(wall, last_fetch_time, None))
21-
time.sleep(1)
22-
23-
if private_walls is not None:
24-
for wall in private_walls:
2520
posts.extend(_get_wall_posts(wall, last_fetch_time, access_token))
2621
time.sleep(1)
2722

@@ -31,8 +26,7 @@ def _get_wall_posts(wall, last_fetch_time, access_token):
3126
logger.debug('_get_wall_posts(%s, %s)', wall, last_fetch_time)
3227

3328
new_posts = []
34-
url = constants.VK_PUBLIC_WALL_URL.format(wall) if access_token is None \
35-
else constants.VK_PRIVATE_WALL_URL.format(wall, access_token)
29+
url = constants.VK_WALL_URL.format(wall, access_token)
3630

3731
requests_ok = False
3832
for num in range(1,5):

src/vk_to_telegram.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ def _read_config(config_file):
1818
config_json = json.loads(open(config_file).read())
1919

2020
public_walls = config_json['public_walls'] if 'public_walls' in config_json else None
21-
private_walls = config_json['private_walls'] if 'private_walls' in config_json else None
2221
bot_token = config_json['telegram_bot_token']
2322
user_ids = config_json['user_ids']
2423
access_token = config_json['vk_access_token'] if 'vk_access_token' in config_json else None
25-
return public_walls, private_walls, bot_token, user_ids, access_token
24+
return public_walls, bot_token, user_ids, access_token
2625

2726

2827
def main(argv):
@@ -45,7 +44,7 @@ def main(argv):
4544
config_file = realpath(args[0])
4645

4746
logfile = config_file.replace('json', 'log')
48-
logging.basicConfig(format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', datefmt='%m/%d/%Y %H:%M:%S %Z', filename=logfile, level=logging.INFO)
47+
logging.basicConfig(format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', datefmt='%m/%d/%Y %H:%M:%S %Z', filename=logfile, level=logging.WARNING)
4948
logger = logging.getLogger('vk_to_telegram')
5049
storagefile = config_file.replace('json', 'last_check')
5150

@@ -67,10 +66,10 @@ def main(argv):
6766

6867
try:
6968

70-
public_walls, private_walls, bot_token, user_ids, access_token = _read_config(config_file)
69+
public_walls, bot_token, user_ids, access_token = _read_config(config_file)
7170
while True:
7271
fetch_time = int(time.time())
73-
posts = vk_fetcher.fetch(public_walls, private_walls, last_fetch_time, access_token)
72+
posts = vk_fetcher.fetch(public_walls, last_fetch_time, access_token)
7473
last_fetch_time = fetch_time
7574
with open(storagefile, "w") as text_file:
7675
text_file.write(str(fetch_time) + "\n")

0 commit comments

Comments
 (0)