Skip to content

Commit

Permalink
Merge pull request #4 from ecoron/0.4.2
Browse files Browse the repository at this point in the history
start adding CsvWriter, add logo
  • Loading branch information
Ronald Schmidt authored Apr 12, 2017
2 parents 4cdb876 + 42328cc commit 86738a2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions serpscrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from serpscrap.config import Config
from serpscrap.serpscrap import SerpScrap
from serpscrap.urlscrape import UrlScrape
from serpscrap.csv_writer import CsvWriter
from serpscrap.markovi import Markovi
from serpscrap.serpscrap import SerpScrap
from serpscrap.tfidf import TfIdf
from serpscrap.urlscrape import UrlScrape
2 changes: 1 addition & 1 deletion serpscrap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Config():
'output_filename': None,
# 'print_results': 'all',
'scrape_urls': True,
'url_threads': 3,
'url_threads': 6,
'log_level': 'INFO',
'num_workers': 1,
'num_results_per_page': 10,
Expand Down
17 changes: 17 additions & 0 deletions serpscrap/csv_writer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
import csv
import traceback


class CsvWriter():

def write(self, file_name, my_dict):
try:
with open(file_name, 'w', encoding='utf-8') as f:
w = csv.DictWriter(f, my_dict[0].keys(), dialect='excel')
w.writeheader()
for row in my_dict[1:]:
w.writerow(row)
except Exception:
print(traceback.print_exc())
raise Exception
8 changes: 8 additions & 0 deletions serpscrap/serpscrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import chardet
from scrapcore.core import Core
from serpscrap.config import Config
from serpscrap.csv_writer import CsvWriter
from serpscrap.urlscrape import UrlScrape


Expand Down Expand Up @@ -88,6 +89,13 @@ def run(self):
results[index].update(result_url)
return results if isinstance(results, list) else [results]

def as_csv(self, file_path):
writer = CsvWriter()
index = 0
result = self.run()
writer.write(file_path + '0' + str(index) + '.csv', result)


def scrap_serps(self):
"""call scrap method and append serp results to list
Returns
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages

version = '0.4.1'
version = '0.4.2'


setup(
Expand Down

0 comments on commit 86738a2

Please sign in to comment.