You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
HSNHK 9fbfd97dc4 add package.js 11 months ago
client shot 11 months ago
server add package.js 11 months ago
README.md update readme 11 months ago

README.md

Fetch product Powered by rayconnect

This project is for fetching the desired information from the site of Digi Kala
The information it extracts from the site includes the following
Product image
Product name and ID
price product
Show discount percentage if available
Seller information
Number of stars
Number of comments

Function

On the client side, the product code is sent to the server, and if the server has not previously stored the product information in its system, it will fetch the information from the site.

Structure

element.js : site element token
Fetch.js : A function for fetching information
log.js : log function
permissions.js : client permissions
server.js : server functions
storage.js : storage class

server

miapp.Query({
      scope: "digikala",
      address: "get_data",
      method: "SEND",
  }, (data) => {
      log.log("user : " + data.token);
      log.log("data : " + data.data);
      client.Get(data.data).then((resolvget)=>{
        if (!resolvget){
            Fetch.FetchData(data.data).then((resolv) => {
                log.log("no data repet : "+data.data)
                data.send(JSON.stringify(resolv))
                client.Add(data.data, JSON.stringify(resolv))
            }).catch(console.log)
        }else{
          log.log("repet data : " + data.data);
          data.send(resolvget)
        }
      }).catch(console.log)
  })

According to the above code, when a request is sent to us, the cache is checked first, and if the data is repeated, the information is sent from the cache. Otherwise, the information is fetched and stored in the cache. The information is sent as a string and parsed in the client.

storage

class Redis_Storage{
    //create redis client in constructor
    constructor(){
        this.client = redis.createClient();
        this.client.on("error", function (error) {
            console.error(error);
        });
    }
    //add new item to redis with key and value
    async Add(key,value){
        await this.client.set(key,value,(err,status)=>{
            if(err!=null)return log.log(err)
            log.log(status)
        })
    }
    //get redis value with key
    Get(key){
        return new Promise((resolv,reject)=>{
            this.client.get(key,(err,value)=>{
                if(err)return reject(err)
                if(value==null)return resolv(null)
                resolv(value)
            })
        })
    }
    ....
}

The storage class contains methods stored in the Redis database

Dependencies

  "dependencies": {
    "cheerio": "^1.0.0-rc.3",
    "rayconnect-client": "^0.11.6-pony",
    "redis": "^3.0.2",
    "request": "^2.88.2",
    "request-promise": "^4.2.6"
  }