Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Created May 15, 2009 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheresalice/112197 to your computer and use it in GitHub Desktop.
Save wheresalice/112197 to your computer and use it in GitHub Desktop.
redacted code which goes through a Drupal database subscribing all new users to a Mailman list on a separate server. Relies upon Drupal Drush module and Mailman XMLRPC2 patch.
import os
import xmlrpclib
proxy = xmlrpclib.ServerProxy("https://lists.mydomain.org/mailman/RPC2")
def nicepass(alpha=6,numeric=2):
"""
returns a human-readble password (say rol86din instead of
a difficult to remember K8Yn9muL )
"""
import string
import random
vowels = ['a','e','i','o','u']
consonants = [a for a in string.ascii_lowercase if a not in vowels]
digits = string.digits
####utility functions
def a_part(slen):
ret = ''
for i in range(slen):
if i%2 ==0:
randid = random.randint(0,20) #number of consonants
ret += consonants[randid]
else:
randid = random.randint(0,4) #number of vowels
ret += vowels[randid]
return ret
def n_part(slen):
ret = ''
for i in range(slen):
randid = random.randint(0,9) #number of digits
ret += digits[randid]
return ret
####
fpl = alpha/2
if alpha % 2 :
fpl = int(alpha/2) + 1
lpl = alpha - fpl
start = a_part(fpl)
mid = n_part(numeric)
end = a_part(lpl)
return "%s%s%s" % (start,mid,end)
if __name__ == "__main__":
os.system(" cd /home/myuser/public_html/ && /usr/local/php5/bin/php drush sql query \"select mail from users
where status=1 and unix_timestamp(date_sub(now(), interval 24 hour)) <= created\" | sed 1d > /home/qwep/newusers")
for line in open("/home/myuser/newusers"):
print line[:-1]
try:
proxy.Mailman.addMember("oursite-announce", "mypassword", line[:-1], "auto-subscribed user", nicepass(6,2), 'false', 'false')
except xmlrpclib.Fault:
print "unexpected error, probably already a member"
try:
os.remove("/home/myuser/newusers")
except OSError:
raise OSError("Couldn't remove the working file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment