API interface to the Python version of the Webpower EDM

Source: Internet
Author: User
Tags addgroup

Webpower seems to provide only the Php,java,.net interface, just to use the Python interface, so the reference to the PHP interface to write a webpower interface

Python version:

#-*-coding:utf-8-*-import os,sys,traceback,time reload (SYS) sys.setdefaultencoding (' Utf-8 ') from suds.client import C Lient class Webpower (object): "" "DocString for Webpower" "Def __init__ (Self, arg): Super (Webpower, self) . __init__ () Self.arg = arg self.client = None Self.url = self.arg.get (' url ', ') SELF.L
        Ogin = self.arg.get (' login ', {}) def connection (self): ' Create connection ' self.client = Client (Self.url) Self.client.set_options (headers={"Content-type": "Text/xml;
            Charset=utf-8 "}" def createsenderaddress (Self,fromemail = '): "Create sent mail address  @param fromemail @return Dict ' ' resultdict = {} try:if not self.client : Self.connection () Tmpresult = self.client.service.createSenderAddress (self.login,fromemail) I F hasattr (Tmpresult, ' statusmsg '): resultdict[' statusmsg '] = tmpresult.statusmsg if Hasattr (tmpresult, ' id '): resultdict[' id ' = tmpresult.id except: resultdict[' ERROR ' = Traceback.format_exc () return resultdict def createcampaign (self,campaign        Name = ', defaultsendername= ', defaultsenderaddrid= ']: ' Create activity @param campaignname 
        The activity name @param defaultsendername sender name @param defaultsenderaddrid send the ID address return Dict  ' ' resultdict = {} try:if not self.client:self.connection () Tmpresult = Self.client.service.createCampaign (self.login, 0, #brandID CAMPAIGNN Ame, #The name of the new campaign defaultsendername, #default Sender name Defaul Tsenderaddrid, #default Sender address Id 0, #default Reply address ' cn '
 , #lang               False, #is overall "", "", "" " If Hasattr (Tmpresult, ' status '): resultdict[' status ' = Tmpresult.status if has attr (Tmpresult, ' id '): resultdict[' id ' = tmpresult.id except:resultdict [' ERROR '] = Traceback.format_exc () return resultdict def createmailing (self,campaignid= ', title = ', Fromna me = ', html = ']: ' Create activity corresponding message content @param campaignid activity ID @param title activity Mark
        Title/Activity Unique header @param fromname Source name @param html HTML content sent @return Dict ' "  Resultdict = {} try:if not self.client:self.connection () Mailingname = '%s_%s '% (title, int (Time.time ())) Tmpresult = self.client.service.createMailing (self.login, campaign
 ID, #campaign ID               Mailingname, #mailing Name ' cn ', #lang title, #              Subject FromName, #fromName 0, #sender ID html #html) if hasattr (Tmpresult, ' status '): resultdict[' status ' = Tmpr
            Esult.status if Hasattr (tmpresult, ' id '): resultdict[' id ' = tmpresult.id except: resultdict[' ERROR ' = Traceback.format_exc () return resultdict def getmailingstatssummary (Self,campai Gnid= ', mailingid= '): ' To get the message sent by mail ID @param campaignid brand ID @param mai Lingid Message ID @return Dict ' resultdict = {} try:if not self.client:se Lf.connection () Tmpresult = Self.client.service.getMailingStatsSummary (Self.login, Campaignid
     , #campaign ID           Mailingid, #mailing ID) resultdict[' result ' = Dict (tmpresult) except : resultdict[' error '] = Traceback.format_exc () return resultdict def addrecipient (Self,campaignid = ', groupids =[],recipientdata = []): ' Add a piece of data to the group @param Campaignid product Card ID @param groupids Group ID @param recipientdata Added DataSet example: [{' name ': ' Email ', ' value ': ' Xx@shopex '. CN '}] return Dict ' "resultdict = {} try:if not Self.client:self.conne Ction () #数组结构 arrayofint = self.client.factory.create (' Arrayofinttype ') arrayofint.in t = Groupids #NewRecipient Structure newrecipientdatatype = self.client.factory.create (' Newrecipienttype ' ) Newrecipientdatatype.fields = Recipientdata Tmpresult = Self.client.service.addRecipient (self. Login, CAmpaignid, #campaign ID arrayofint, #groupIDs arrayofint1 Newrec
            Ipientdatatype, #recipient Data recipientdata true, True) resultdict[' result ' = Dict (tmpresult) except:resultdict[' ERROR ' = Traceback.format_exc () re Turn resultdict def addgroup (Self,campaignid = ', name = '): ' Add group @param campaigni
            D Brand ID @param name group names @return Dict ' resultdict = {} try: If not self.client:self.connection () #NewGroupType newgrouptype = Self.client.factory.cre Ate (' newgrouptype ') newgrouptype.name = name newgrouptype.is_test = True Newgrouptype. remarks = ' Tmpresult = Self.client.service.addGroup (Self.login, Campaignid, #
            Campaign ID    Newgrouptype, #New Group Type) resultdict[' result ' = Dict (Tmpresult) except:resultdict[' ERROR ' = Traceback.format_exc () return resultdict def sendmailing (Self,cam Paignid = ', mailingid= ', resultsemail= ', groupids=[],callbackurl= '): ' Send mail @param camp Aignid Brand ID @param mailingid Message ID @param istest is a test @param resultsemail knot
        Fruit Email @param groupids Group ID @param callbackurl return URL @return Dict ' " Resultdict = {} try:if not self.client:self.connection () #groupIDs A
            Rrayofinttype = self.client.factory.create (' arrayofinttype ') Arrayofinttype.int = Groupids #langs Arrayofstringtype = self.client.factory.create (' arrayofstringtype ') arrayofstringtype.string = [' C N '] TmpresUlt = self.client.service.sendMailing (Self.login, Campaignid, #campaign ID Mailingi
                D, #mailing ID False, #is test resultsemail, #results Email
                Arrayofinttype, #group IDs 0, Arrayofstringtype, #langs ', Callbackurl) resultdict[' result ' = Dict (tmpresult) except:re sultdict[' ERROR ' = Traceback.format_exc () return resultdict def sendsinglemailing (self,campaignid= ", mailing  Id= ', recipientid= '): ' Send a single email @param campaignid brand ID @param mailingid
        Email address sent @param recipientid recipient ID @return Dict ' resultdict = {} Try:if not self.client:self.connection () Tmpresult = self.client.service.sendSingleMailing (
            Self.login,    Campaignid, #campaign ID mailingid, #mailing ID recipientid, #is tes T) resultdict[' result '] = {' Status ': Tmpresult} except:resultdict[' Error '] = Traceback.format_exc () return resultdict if __name__ = = ' __main__ ': arg = {' login ': {' Usernam E ': ' Password ': ' http://******.dmdelivery.com/x/soap-v4/wsdl.php '}, ' url ': ' The Web Power (ARG). createsenderaddress (' wangzhaoming@shopex.cn ') #print webpower (ARG). Createcampaign (' 1sssss ') #print WEBP Ower (ARG). createmailing (237, ' subjecttest22 ', ' 67272740 ', '  


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.