-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
101 lines (78 loc) · 3.43 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from datetime import datetime, timedelta
import PICPA_La_Robot as Bot
if __name__ == '__main__':
inbox = Bot.OutlookInboxFolder('PICPA')
inbox.show_body_links = False
end_date = datetime.now().date()
last_week = end_date - timedelta(days=7)
current_mail_items = inbox.folder_restrict(
f"[ReceivedTime] >= '{last_week.strftime('%m/%d/%Y %H:%M %p')}'"
)
print('Getting Outlook items from', end=' ')
print(f"{last_week.strftime('%b/%d/%Y')} to {end_date.strftime('%b/%d/%Y')}")
contents = []
for items in current_mail_items:
for subject, body in items.items():
for_replacement = {
"If you can't see this email click here.": '',
'\t' : " ",
'\r' : '',
'Marvin' : 'Redditor',
'Share this event' : '',
'When' : '',
' \n' : '\n\n',
'\n \n' : '',
'\n  ' : '\n\n',
'\nSPEAKER' : ' | **SPEAKER**',
'Speakers' : '## Speakers',
' I Will Attend \n' : '' ,
'\n No ' : '' ,
'Register Now': '',
'Register' : '',
' Learn more' : ''
}
body = Bot.chain_replace(body, replace=for_replacement)
body = body.strip()
footer = body.find('Unsubscribe')
body = body[0:footer]
speakers = body.find('Speakers')
body_speakers = body[speakers:]
body = body[0:speakers]
body_speakers = body_speakers.split('\n')
body_speakers = '\n\n'.join(body_speakers)
body = body + body_speakers
decor = '¤' * min(48, len(subject)) + '\n'
contents.append(
f"{decor}\n## {subject}\n\n{decor}\n{body}"
)
contents = [cont + '\n---\n' for cont in contents]
CHAR_LIMIT = 30000
char_len_count = 0
comments = []
for n, item in enumerate(contents):
char_len_count += len(item)
if char_len_count >= CHAR_LIMIT:
slicer = n
comments = contents[slicer:]
contents = contents[0:slicer]
break
continue_to_post = input('Done getting data from Outlook. Should we continue?\n')
if continue_to_post.lower() in ['y', 'yes']:
try:
reddit = Bot.RedditInstance('PICPA_La_Robot', user_agent='script/PICPA_La_Robot')
reddit.post_title = (f"This is PICPA for the week ending {end_date.strftime('%B %d, %Y')}")
reddit.append_body('# PICPA WEEKLY')
reddit.append_body('These are summary of new PICPA Events from', end=' ')
reddit.extend_body_last(f"{last_week.strftime('%b %d')} to {end_date.strftime('%b %d')}.")
reddit.append_body('You can register for these events at the', end=' ')
reddit.extend_body_last('[PICPA GlueUp website](https://picpa.glueup.com/).', end='\n\n')
reddit.append_body(contents)
reddit.append_body('^(I am a bot in alpha. For concerns, contact', end=' ')
reddit.extend_body_last('[tagapagtuos](https://www.reddit.com/user/tagapagtuos).)')
reddit.post('AccountingPH')
for item in comments:
reddit.comment_on_post(item)
except Exception as e:
print(e)
else:
print('I will take that as a NO.')