Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:32:23+00:00 2026-06-15T18:32:23+00:00

I’m very new to coding in general, so I apologize ahead of time if

  • 0

I’m very new to coding in general, so I apologize ahead of time if this question should be rather obvious. Here’s what I’m looking to do, and following that I’ll post the code I’ve used so far.

I’m trying to get gzip’d csv rank data from a website and store it into a database, for a clan website that I’m working on developing. Once I get this figured out, I’ll need to grab the data once every 5 minutes. The grabbing the csv data I’ve been able to accomplish, although it stores it into a text file and I need to store it into mongodb.

Here’s my code:

var DB        =    require('../modules/db-settings.js');
var http      =    require('http');
var zlib      =    require('zlib');
var fs        =    require('fs');
var mongoose  =    require('mongoose');
var db          =   mongoose.createConnection(DB.host, DB.database, DB.port, {user: DB.user, pass: DB.password});

var request = http.get({ host: 'www.earthempires.com',
                     path: '/ranks_feed?apicode=myapicode',
                     port: 80,
                     headers: { 'accept-encoding': 'gzip' } });
request.on('response', function(response) {
  var output = fs.createWriteStream('./output');

  switch (response.headers['content-encoding']) {
    // or, just use zlib.createUnzip() to handle both cases
    case 'gzip':
      response.pipe(zlib.createGunzip()).pipe(output);
      break;
    default:
      response.pipe(output);
      break;
  }
});

db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
  var rankSchema = new mongoose.Schema({
    serverid: Number,
    resetid: Number,
    rank: Number,
    countryNumber: Number,
    name: String,
    land: Number,
    networth: Number,
    tag: String,
    gov: String,
    gdi: Boolean,
    protection: Boolean,
    vacation: Boolean,
    alive: Boolean,
    deleted: Boolean
  })
});

Here’s an example of what the csv will look like(first 5 lines of file):

9,386,1,451,Super Kancheong Style,22586,318793803,LaF,D,1,0,0,1,0
9,386,2,119,Storm of Swords,25365,293053897,LaF,D,1,0,0,1,0
9,386,3,33,eug gave it to mak gangnam style,43501,212637806,LaF,H,1,0,0,1,0
9,386,4,128,Justpickupgirlsdotcom,22628,201606479,LaF,H,1,0,0,1,0
9,386,5,300,One and Done,22100,196130870,LaF,H,1,0,0,1,0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:32:23+00:00Added an answer on June 15, 2026 at 6:32 pm

    Hope it’s not too late to help, but here’s what I’d do:

    1. Request the CSV formatted data and store it in memory or a file.
    2. Parse the CSV data to convert each row into an object.
    3. For each object, use Model.create() to create your new entry.

    First, you need to create a model from your Schema:

    var Rank = db.model('Rank', rankSchema);
    

    Then you can parse your block of CSV text (whether you read it from a file or do it directly after your request is up to you.) I created my own bogus data variable since I don’t have access to the api, but as long as your data is a newline delimited block of CSV text this should work:

    /* Data is just a block of CSV formatted text. This can be read from a file                                                                                                  
       or retrieved right in the response. */                                                                                                                                    
    var data = '' +                                                                                                                                                              
        '9,386,1,451,Super Kancheong Style,22586,318793803,LaF,D,1,0,0,1,0\n' +                                                                                                  
        '9,386,2,119,Storm of Swords,25365,293053897,LaF,D,1,0,0,1,0\n' +                                                                                                        
        '9,386,3,33,eug gave it to mak gangnam style,43501,212637806,LaF,H,1,0,0,1,0\n' +                                                                                        
        '9,386,4,128,Justpickupgirlsdotcom,22628,201606479,LaF,H,1,0,0,1,0\n' +                                                                                                  
        '9,386,5,300,One and Done,22100,196130870,LaF,H,1,0,0,1,0\n';                                                                                                            
    
    data = data.split('\n');                                                                                                                                                     
    
    data.forEach(function(line) {                                                                                                                                                
        line = line.split(',');   
    
        if (line.length != 14)
            return;                                                                                                                                               
    
        /* Create an object representation of our CSV data. */                                                                                                                   
        var new_rank = {                                                                                                                                                         
            serverid: line[0],                                                                                                                                                   
            resetid: line[1],                                                                                                                                                    
            rank: line[2],                                                                                                                                                       
            countryNumber: line[3],                                                                                                                                              
            name: line[4],                                                                                                                                                       
            land: line[5],                                                                                                                                                       
            networth: line[6],                                                                                                                                                   
            tag: line[7],                                                                                                                                                        
            gov: line[8],                                                                                                                                                        
            gdi: line[9],                                                                                                                                                        
            protection: line[10],                                                                                                                                                
            vacation: line[11],                                                                                                                                                  
            alive: line[12],                                                                                                                                                     
            deleted: line[13]                                                                                                                                                    
        };                                                                                                                                                                       
    
        /* Store the new entry in MongoDB. */                                                                                                                                    
        Rank.create(new_rank, function(err, rank) {                                                                                                                            
            console.log('Created new rank!', rank);                                                                                                                              
        });                                                                                                                                                                      
    });
    

    You could put this in a script and run it every 5-minutes using a cron job. On my Mac, I’d edit my cron file with crontab -e, and I’d setup a job with a line like this:

    */5 * * * * /path/to/node /path/to/script.js > /dev/null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.