Filesize is unproportional











up vote
0
down vote

favorite












A webscraper written in Python extracts waterleveldata. One read per hour.
When written to a .txt-file using the code below each line is appended with datetime, thus each line takes up something like 20 characters.
Example: "01/01-2010 11:10,-32"



Using the code below results in a file containing data from 01/01-2010 00:10 to 28/02-2010 23:50 which equals something like 60 days. 60 days, with a reading per hour results in 1440 lines and approx. 30000 characters. Microsoft word, however, tell me the file contains 830000 characters on 42210 lines, which fits very well with an observed filesize of 893 kB.



Apparently some lines and characters are hidden somewhere. I cant seem to find them anywhere.



import requests
import time

totaldata =
filnavn='Vandstandsdata_Esbjerg_KDI_TEST_recode.txt'
file = open(filnavn,'w')
file.write("")
file.close()

from datetime import timedelta, date
from bs4 import BeautifulSoup

def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)

start_date = date(2010, 1, 1)
end_date = date(2010, 3, 1)
values=
datoer=
for single_date in daterange(start_date, end_date):
valuesTemp=
datoerTemp=
dato = single_date.strftime("%d-%m-%y")
url = "http://kysterne.kyst.dk/pages/10852/waves/showData.asp?targetDay="+dato+"&ident=6401&subGroupGuid=16410"
page = requests.get(url)
if page.status_code == 200:
soup = BeautifulSoup(page.content, 'html.parser')
dataliste = list(soup.find_all(class_="dataTable"))
#dataliste =list(dataliste.find_all('td'))
#dataliste =dataliste[0].getText()
print(url)
dataliste = str(dataliste)
dataliste = dataliste.splitlines()
dataliste = dataliste[6:] #18
#print(dataliste[0])
#print(dataliste[1])
for e in range (0,len(dataliste),4): #4
#print(dataliste[e])
datoerTemp.append(dataliste[e])
#print(" -------- n")
for e in range (1,len(dataliste),4): #4
valuesTemp.append(dataliste[e])
for e in valuesTemp:
#print (e)
e=e[4:]
e=e[:-5]
values.append(e)
for e in datoerTemp:
#print (e)
e=e[4:]
e=e[:-5]
datoer.append(e)

file = open(filnavn,'a')
for i in range(0,len(datoer),6):
file.write(datoer[i]+","+values[i]+"n")
print("- skrevet til filn")
file.close()
print("done")









share|improve this question




























    up vote
    0
    down vote

    favorite












    A webscraper written in Python extracts waterleveldata. One read per hour.
    When written to a .txt-file using the code below each line is appended with datetime, thus each line takes up something like 20 characters.
    Example: "01/01-2010 11:10,-32"



    Using the code below results in a file containing data from 01/01-2010 00:10 to 28/02-2010 23:50 which equals something like 60 days. 60 days, with a reading per hour results in 1440 lines and approx. 30000 characters. Microsoft word, however, tell me the file contains 830000 characters on 42210 lines, which fits very well with an observed filesize of 893 kB.



    Apparently some lines and characters are hidden somewhere. I cant seem to find them anywhere.



    import requests
    import time

    totaldata =
    filnavn='Vandstandsdata_Esbjerg_KDI_TEST_recode.txt'
    file = open(filnavn,'w')
    file.write("")
    file.close()

    from datetime import timedelta, date
    from bs4 import BeautifulSoup

    def daterange(start_date, end_date):
    for n in range(int ((end_date - start_date).days)):
    yield start_date + timedelta(n)

    start_date = date(2010, 1, 1)
    end_date = date(2010, 3, 1)
    values=
    datoer=
    for single_date in daterange(start_date, end_date):
    valuesTemp=
    datoerTemp=
    dato = single_date.strftime("%d-%m-%y")
    url = "http://kysterne.kyst.dk/pages/10852/waves/showData.asp?targetDay="+dato+"&ident=6401&subGroupGuid=16410"
    page = requests.get(url)
    if page.status_code == 200:
    soup = BeautifulSoup(page.content, 'html.parser')
    dataliste = list(soup.find_all(class_="dataTable"))
    #dataliste =list(dataliste.find_all('td'))
    #dataliste =dataliste[0].getText()
    print(url)
    dataliste = str(dataliste)
    dataliste = dataliste.splitlines()
    dataliste = dataliste[6:] #18
    #print(dataliste[0])
    #print(dataliste[1])
    for e in range (0,len(dataliste),4): #4
    #print(dataliste[e])
    datoerTemp.append(dataliste[e])
    #print(" -------- n")
    for e in range (1,len(dataliste),4): #4
    valuesTemp.append(dataliste[e])
    for e in valuesTemp:
    #print (e)
    e=e[4:]
    e=e[:-5]
    values.append(e)
    for e in datoerTemp:
    #print (e)
    e=e[4:]
    e=e[:-5]
    datoer.append(e)

    file = open(filnavn,'a')
    for i in range(0,len(datoer),6):
    file.write(datoer[i]+","+values[i]+"n")
    print("- skrevet til filn")
    file.close()
    print("done")









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      A webscraper written in Python extracts waterleveldata. One read per hour.
      When written to a .txt-file using the code below each line is appended with datetime, thus each line takes up something like 20 characters.
      Example: "01/01-2010 11:10,-32"



      Using the code below results in a file containing data from 01/01-2010 00:10 to 28/02-2010 23:50 which equals something like 60 days. 60 days, with a reading per hour results in 1440 lines and approx. 30000 characters. Microsoft word, however, tell me the file contains 830000 characters on 42210 lines, which fits very well with an observed filesize of 893 kB.



      Apparently some lines and characters are hidden somewhere. I cant seem to find them anywhere.



      import requests
      import time

      totaldata =
      filnavn='Vandstandsdata_Esbjerg_KDI_TEST_recode.txt'
      file = open(filnavn,'w')
      file.write("")
      file.close()

      from datetime import timedelta, date
      from bs4 import BeautifulSoup

      def daterange(start_date, end_date):
      for n in range(int ((end_date - start_date).days)):
      yield start_date + timedelta(n)

      start_date = date(2010, 1, 1)
      end_date = date(2010, 3, 1)
      values=
      datoer=
      for single_date in daterange(start_date, end_date):
      valuesTemp=
      datoerTemp=
      dato = single_date.strftime("%d-%m-%y")
      url = "http://kysterne.kyst.dk/pages/10852/waves/showData.asp?targetDay="+dato+"&ident=6401&subGroupGuid=16410"
      page = requests.get(url)
      if page.status_code == 200:
      soup = BeautifulSoup(page.content, 'html.parser')
      dataliste = list(soup.find_all(class_="dataTable"))
      #dataliste =list(dataliste.find_all('td'))
      #dataliste =dataliste[0].getText()
      print(url)
      dataliste = str(dataliste)
      dataliste = dataliste.splitlines()
      dataliste = dataliste[6:] #18
      #print(dataliste[0])
      #print(dataliste[1])
      for e in range (0,len(dataliste),4): #4
      #print(dataliste[e])
      datoerTemp.append(dataliste[e])
      #print(" -------- n")
      for e in range (1,len(dataliste),4): #4
      valuesTemp.append(dataliste[e])
      for e in valuesTemp:
      #print (e)
      e=e[4:]
      e=e[:-5]
      values.append(e)
      for e in datoerTemp:
      #print (e)
      e=e[4:]
      e=e[:-5]
      datoer.append(e)

      file = open(filnavn,'a')
      for i in range(0,len(datoer),6):
      file.write(datoer[i]+","+values[i]+"n")
      print("- skrevet til filn")
      file.close()
      print("done")









      share|improve this question















      A webscraper written in Python extracts waterleveldata. One read per hour.
      When written to a .txt-file using the code below each line is appended with datetime, thus each line takes up something like 20 characters.
      Example: "01/01-2010 11:10,-32"



      Using the code below results in a file containing data from 01/01-2010 00:10 to 28/02-2010 23:50 which equals something like 60 days. 60 days, with a reading per hour results in 1440 lines and approx. 30000 characters. Microsoft word, however, tell me the file contains 830000 characters on 42210 lines, which fits very well with an observed filesize of 893 kB.



      Apparently some lines and characters are hidden somewhere. I cant seem to find them anywhere.



      import requests
      import time

      totaldata =
      filnavn='Vandstandsdata_Esbjerg_KDI_TEST_recode.txt'
      file = open(filnavn,'w')
      file.write("")
      file.close()

      from datetime import timedelta, date
      from bs4 import BeautifulSoup

      def daterange(start_date, end_date):
      for n in range(int ((end_date - start_date).days)):
      yield start_date + timedelta(n)

      start_date = date(2010, 1, 1)
      end_date = date(2010, 3, 1)
      values=
      datoer=
      for single_date in daterange(start_date, end_date):
      valuesTemp=
      datoerTemp=
      dato = single_date.strftime("%d-%m-%y")
      url = "http://kysterne.kyst.dk/pages/10852/waves/showData.asp?targetDay="+dato+"&ident=6401&subGroupGuid=16410"
      page = requests.get(url)
      if page.status_code == 200:
      soup = BeautifulSoup(page.content, 'html.parser')
      dataliste = list(soup.find_all(class_="dataTable"))
      #dataliste =list(dataliste.find_all('td'))
      #dataliste =dataliste[0].getText()
      print(url)
      dataliste = str(dataliste)
      dataliste = dataliste.splitlines()
      dataliste = dataliste[6:] #18
      #print(dataliste[0])
      #print(dataliste[1])
      for e in range (0,len(dataliste),4): #4
      #print(dataliste[e])
      datoerTemp.append(dataliste[e])
      #print(" -------- n")
      for e in range (1,len(dataliste),4): #4
      valuesTemp.append(dataliste[e])
      for e in valuesTemp:
      #print (e)
      e=e[4:]
      e=e[:-5]
      values.append(e)
      for e in datoerTemp:
      #print (e)
      e=e[4:]
      e=e[:-5]
      datoer.append(e)

      file = open(filnavn,'a')
      for i in range(0,len(datoer),6):
      file.write(datoer[i]+","+values[i]+"n")
      print("- skrevet til filn")
      file.close()
      print("done")






      python python-3.x web-scraping






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 8:40

























      asked Nov 22 at 8:26









      Mathias

      961312




      961312
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Ah, heureka.



          Seconds before posting this question I realized I forgot to reset the list.
          I added:



          datoer=


          everything now works as intended.
          The old code would write data from a given day and all data of all previous days, for each loop in the code.
          I hope someone can use this newbie-experience.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426662%2ffilesize-is-unproportional%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Ah, heureka.



            Seconds before posting this question I realized I forgot to reset the list.
            I added:



            datoer=


            everything now works as intended.
            The old code would write data from a given day and all data of all previous days, for each loop in the code.
            I hope someone can use this newbie-experience.






            share|improve this answer



























              up vote
              0
              down vote













              Ah, heureka.



              Seconds before posting this question I realized I forgot to reset the list.
              I added:



              datoer=


              everything now works as intended.
              The old code would write data from a given day and all data of all previous days, for each loop in the code.
              I hope someone can use this newbie-experience.






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                Ah, heureka.



                Seconds before posting this question I realized I forgot to reset the list.
                I added:



                datoer=


                everything now works as intended.
                The old code would write data from a given day and all data of all previous days, for each loop in the code.
                I hope someone can use this newbie-experience.






                share|improve this answer














                Ah, heureka.



                Seconds before posting this question I realized I forgot to reset the list.
                I added:



                datoer=


                everything now works as intended.
                The old code would write data from a given day and all data of all previous days, for each loop in the code.
                I hope someone can use this newbie-experience.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 at 8:39

























                answered Nov 22 at 8:26









                Mathias

                961312




                961312






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426662%2ffilesize-is-unproportional%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Futebolista

                    F# list compare

                    Jornalista