Ejemplo n.º 1
0
    def items(self):
	# Article is model defined in Atom2RETS
        arts =  Article.objects.all() 
        arts.delete() #clear it out
      
        if(self.error == "true"):
            print "error! " +self.error_desc
            aa = Article()
            aa.title = "ERROR"
            aa.description = self.error_desc#results.GetCount()
            aa.link = "" #In future implementation perhaps link to listing source webpage
            aa.save()
            return arts

        #
        #  RETS STUFF
        #

    	import librets
    	import sys
    	import time
    	        	
    	#Kept having problems with CRT RETS Server saying additional logins not allowed, the retries below address the issue as a work-around
        login = False
        ct = 1
        
        loginurl = self.config['activeserver']['server']['loginurl']
        
        while(ct <= 10):
            #print "login attempt " + str(ct)
            try:
                
            	session = None
            	session = librets.RetsSession(loginurl)
                session.SetHttpLogName("log"+".txt")
                session.SetUserAgent("Data Wrap/1.0")
                #override user and password if sent in URL
                if(len(self.user) > 0):
                    print "rets user is " + self.user
                if(len(self.password) > 0):
                    print "rets password is " + self.password                
                if (not session.Login(str(self.user), str(self.password))):
                    ct += 1
                    time.sleep(1)
                else:
            	    login = True
            	    break
            except librets.RetsException as (errno, strerror):
                print "RETS error({0}): {1}".format(errno, strerror)            
            except:
Ejemplo n.º 2
0
        titl = "TITL"      
        
          
        for rec in join:            
            rec_class = rec[len(rec)-1]
            print rec_class
            desc = ""
            titl = ""
            index = 0
            #labels = ["ListingID: ", ", ListPrice: ", ", Beds: ", "Baths: ", ", City: ", ", Zipcode: ", ", State: ", ", Status: ", ", StreetName: ", ", StreetNumber: ", ", Year: ", ", Area: "]
            labels = self.config['activeserver']['Categories'][rec_class]['select_fields'].keys()
            labels.append("category")
            for label in labels:
                val = rec[index]
                if label == "price":
                    titl = "$" + val
                desc += labels[index] + ": " + val + ", "
                index += 1            	
            aa = Article()
            aa.title = titl

            aa.description = desc.rstrip(', ')
            print aa.description

            aa.link = ""
            aa.save()

        #print arts      	
        
        return arts