Gebruiker:Edoderoobot/e-mailinglist.py

NoticeBewerken

Before you use the wikimail python tool, there's a few things you should know.

  1. . You're responsible for your use of the tool. Please be careful to comply with your country's rules against spam and illegal content, such as the CAN-SPAM law.
  2. . We may suspend or terminate your access to the tool if you abuse it. Please don't:
  • Harass anyone
  • Spam people
  • Send unsolicited commerical messages
  • Send anything illegal
  • Send sexually explicit or mature content
import pywikibot
import sys
import codecs

site = pywikibot.Site('nl')

userlist=['Edoderoo','SRientjes','SindyM3',
'AnotherUser',
'NothernotherUser',
'LastUser']


def logme(verbose, formatstring, *parameters):
  with codecs.open("mailing.log.csv", "a", encoding="utf-8") as logfile:
    formattedstring = u'%s%s' % (formatstring, '\n')
    try:
      logfile.write(formattedstring % (parameters) )
    except :
      exctype, value = sys.exc_info()[:2]
      print("1) Error writing to logfile on: [%s] [%s]" % (exctype, value))
      verbose = True    #now I want to see what!
    logfile.close()
  if verbose:
    print(formatstring % (parameters))


def mailoneuser(username):
 mailsubject='Thanks for your work for Wikipedia!'
 txt2mail= u'Dear %s,\n\n' % username
 txt2mail+= ('Thanks for your contribution to Wikipedia. We truely appreciate it that you dedicate your time to spead the value of free knowledge.\n\n'
            'We would like to use the opportunity to get your attention to the following:\n\n'
            '* point 1;\n'
            '* point 2;\n'
            '* That\'s it.\n'
            '\n\n\n'
            'Regards,\n\n'
            'Signature 1,\n'
            'Signature 2.\n\n\n')

 wikiuser=pywikibot.User(site,username)
 if not wikiuser.isEmailable():
   logme(False,"User is has no mail: %s", username)
   return(0)
 if wikiuser.isBlocked():
   logme(False,"User is blocked    : %s", username)
   return(0)

 try:
   wikiuser.sendMail(subject=mailsubject, text=txt2mail)
   logme(False,"Succes: %s",  username)
   return(1)
 except:
   logme(True,"Fail on user: %s", username)
   return(0)

def main():
  mailoneuser('Edoderoo')
  for oneuser in userlist:   #loop along all users in the userlist
    mailoneuser(oneuser)     #send the mail to this one user

main()