• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
#!/usr/bin/ruby# require's for the librets and mysql librariesrequire 'librets'require 'mysql'require 'pp'include Librets# Empty value for "values". I can into a problem with line 55 which required me toput this in.values = ""mls_number = ""# Initilizes and connects to the MySQL Databasemysql = Mysql.init()mysql.connect(host='<<database location>>', user='<<db user>>', passwd='<<dbpassword>>')mysql.select_db('Duluth')# Optional: I was going off another Ruby::DBI set of instructions. Only include ifyou want to start from fresh each time.mysql.query("ALTER TABLE residentialpropertyphotos DROP FOREIGN KEYresidentialpropertyphotos_ibfk_1;")mysql.query("DROP TABLE IF EXISTS ResidentialProperty")mysql.query("DROP TABLE IF EXISTS ResidentialPropertyPhotos")#Creates the Database to work with. I pulled the metadata from the RETS feed todetermine what the field types and lengths aremysql.query("CREATE TABLE ResidentialProperty (L_ListingID INT UNSIGNED NOT NULL,PRIMARY KEY (L_ListingID),L_AskingPrice INT NOT NULL, L_Keyword2 INT NOT NULL, L_Keyword3 INTNOT NULL, L_Keyword4 INT, L_City CHAR(50) NOT NULL, L_Area varchar(50) NOT NULL,L_AddressNumber varchar(15) NOT NULL, L_AddressDirection varchar(2),L_AddressStreet varchar(50) NOT NULL, LR_Remarks11 varchar(1000),LA1_UserFirstName varchar(15) NOT NULL, LO1_OrganizationNamevarchar(50) NOT NULL, LO1_PhoneNumber1Area INT,LO1_PhoneNumber1 INT) Type=INNODB;") mysql.query("CREATE TABLE ResidentialPropertyPhotos (PhotoID INT UNSIGNED NOT NULLAUTO_INCREMENT, PRIMARY KEY (PhotoID),L_ListingID INT UNSIGNED NOT NULL, Photo_Number varchar(5) NOT NULL,Photo LONGBLOB,INDEX (L_ListingID), FOREIGN KEY (L_ListingID) REFERENCESResidentialProperty (L_ListingID)) TYPE=INNODB;")# Creates a RETS Sessionsession = RetsSession.new("<<RETS URL>>")# Changes the encodeing from ASCII to ISOsession.set_default_encoding(RETS_XML_ISO_ENCODING)# Login into RETSif !session.login("<<RETS user>>", "<<RETS password>>")puts "Invalid login"exit 1end
 
# Not quite sure what this doesputs "Action: " + session.action# Checks the version of the RETS serverversion = "1.0"version = "1.5" if (session.detected_rets_version == RETS_1_5)puts "RETS Version: " + version# Your DMQL syntax for your search. This search is grabbing all Active Residentiallistings.request = session.create_search_request("Property", "ResidentialProperty","(L_Status=1_0)") #request.standard_names = true # Tells RETS to use standard namesrequest.select ="L_ListingID,L_AskingPrice,L_Keyword2,L_Keyword3,L_City,L_Area,L_AddressNumber,L_AddressDirection,L_AddressStreet,\LR_Remarks11,LA1_UserFirstName,LO1_OrganizationName,LO1_PhoneNumber1Area,LO1_PhoneNumber1" # Fields returned in your searchrequest.limit = SearchRequest::LIMIT_DEFAULT # Requests the RETSServer default limitrequest.offset = SearchRequest::OFFSET_NONE # Indicates no offset tothe RETS serverrequest.count_type = SearchRequest::RECORD_COUNT_AND_RESULTS # Not exactly sureon this oneresults = session.search(request) # Executes the searchcolumns = results.columns # Places results in columnsresults.each do |result| # Iterates through each rowcolumns.each do |column| # Iterates through each columncleaned_value = mysql.escape_string(result.string(column))values += column + "='#{cleaned_value}'," # Creates the set expression forthe INSERT statementendmysql.query("INSERT INTO ResidentialProperty SET #{values.chop};") # Writes theresults to the Databasevalues = ""end# MySQL query to return all active MLS numbersresults = mysql.query("Select L_ListingID FROM ResidentialProperty");# Loop to process each MLS listing and retreive photosresults.each do |row| mls_number = row[0] # Get Object request to pull listing photosget_object_request = GetObjectRequest.new("Property", "Photo")get_object_request.add_all_objects("#{mls_number}") get_object_response = session.get_object(get_object_request) # Assigns each part of the Get Object to a variablecontent_type_suffixes = { "image/jpeg" => "jpg", "image/gif" => "gif","text/xml" => "xml" }get_object_response.each_object do |object_descriptor|object_key = object_descriptor.object_key
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...