Skip to content

Commit

Permalink
Merge pull request #12 from claromes/fix-setup
Browse files Browse the repository at this point in the history
Fix setup
  • Loading branch information
claromes authored Jun 1, 2023
2 parents 2b964a8 + ea67014 commit eeddc29
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 77 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ pip3 install matchscraper
```

## Usage
```shell
```
matchscraper --fed cbv --match 1623
```

```shell
```
.
|`.
| `.
|-_ `.
| -_ `._
____________________|____-_ _|_______________,
', -_| ',
', | ',
', | ',
',_____________________|______________________',
Matchscraper
Matchscraper: started!
Matchscraper: data/1623_22-10-28_home_fluminense.csv file was created!
Expand Down
Binary file added __pycache__/main.cpython-38.pyc
Binary file not shown.
18 changes: 15 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,23 @@ pip3 install matchscraper
```

## Usage
```shell
matchscraper --match cbv 1623
```
matchscraper --fed cbv --match 1623
```

```shell
```
.
|`.
| `.
|-_ `.
| -_ `._
____________________|____-_ _|_______________,
', -_| ',
', | ',
', | ',
',_____________________|______________________',
Matchscraper
Matchscraper: started!
Matchscraper: data/1623_22-10-28_home_fluminense.csv file was created!
Expand Down
64 changes: 0 additions & 64 deletions matchscraper/__main__.py

This file was deleted.

87 changes: 87 additions & 0 deletions matchscraper/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import argparse
import os
import sys
from scrapy.crawler import CrawlerProcess

from matchscraper.spiders.match import HomeStatsSpider, GuestStatsSpider
from matchscraper.spiders.competition import CompetitionMatchesSpider
from matchscraper.version import __version__

version = __version__
welcome_msg = '''
.
|`.
| `.
|-_ `.
| -_ `._
____________________|____-_ _|_______________,
', -_| ',
', | ',
', | ',
',_____________________|______________________',
Matchscraper v{}
'''.format(version)

# https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
started_msg = '\x1b[6;30;42m' + '\n Matchscraper: started! ' + '\x1b[0m\n'
finished_msg = '\x1b[6;30;42m' + '\n Matchscraper: finished! ' + '\x1b[0m\n'

def main():
print(welcome_msg)

parser = argparse.ArgumentParser()

parser.add_argument(
'--fed',
type=str,

help='Federation Acronym'
)

parser.add_argument(
'--match',
type=int,

help='Stats of a single match'
)

parser.add_argument(
'--comp',
type=int,

help='List of matches in a competition'
)

args = vars(parser.parse_args())

process = CrawlerProcess(settings={
'FEEDS': {
'data/%(name)s.csv': {
'format': 'csv',
'overwrite': True
},
},
})

print(started_msg)

if args['match']:
fed_acronym = args['fed']
match_id = args['match']

process.crawl(GuestStatsSpider, fed_acronym=fed_acronym, match_id=match_id)
process.crawl(HomeStatsSpider, fed_acronym=fed_acronym, match_id=match_id)
process.start()

print(finished_msg)
elif args['comp']:
fed_acronym = args['fed']
competition_id = args['comp']

process.crawl(CompetitionMatchesSpider, fed_acronym=fed_acronym, competition_id=competition_id)
process.start()

print(finished_msg)

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions matchscraper/spiders/competition.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ def closed(spider, reason):
try:
os.rename(src, dst)

print('\x1b[6;30;42m' + '\nMatchscraper: {} file was created!'.format(dst) + '\x1b[0m\n')
print('\x1b[6;30;42m' + '\n Matchscraper: {} file was created! '.format(dst) + '\x1b[0m\n')
except(FileExistsError):
print('\x1b[6;30;43m' + '\nMatchscraper: file {} already exists.\n{} was created or renamed!'.format(dst, src) + '\x1b[0m\n')
print('\x1b[6;30;43m' + '\n Matchscraper: file {} already exists.\n{} was created or renamed! '.format(dst, src) + '\x1b[0m\n')
8 changes: 4 additions & 4 deletions matchscraper/spiders/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def closed(spider, reason):
try:
os.rename(src, dst)

print('\x1b[6;30;42m' + '\nMatchscraper: {} file was created!'.format(dst) + '\x1b[0m\n')
print('\x1b[6;30;42m' + '\n Matchscraper: {} file was created! '.format(dst) + '\x1b[0m\n')
except(FileExistsError):
print('\x1b[6;30;43m' + '\nMatchscraper: file {} already exists.\n{} was created or renamed!'.format(dst, src) + '\x1b[0m\n')
print('\x1b[6;30;43m' + '\n Matchscraper: file {} already exists.\n{} was created or renamed! '.format(dst, src) + '\x1b[0m\n')

class GuestStatsSpider(scrapy.Spider):
name = 'guest_stats'
Expand Down Expand Up @@ -119,6 +119,6 @@ def closed(spider, reason):
try:
os.rename(src, dst)

print('\x1b[6;30;42m' + '\nMatchscraper: {} file was created!'.format(dst) + '\x1b[0m\n')
print('\x1b[6;30;42m' + '\n Matchscraper: {} file was created! '.format(dst) + '\x1b[0m\n')
except(FileExistsError):
print('\x1b[6;30;43m' + '\nMatchscraper: file {} already exists.\n{} was created or renamed!'.format(dst, src) + '\x1b[0m\n')
print('\x1b[6;30;43m' + '\n Matchscraper: file {} already exists.\n{} was created or renamed! '.format(dst, src) + '\x1b[0m\n')
2 changes: 1 addition & 1 deletion matchscraper/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.1'
__version__ = '0.2.1.1'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
install_requires=install_requires,
entry_points = {
'console_scripts': [
'matchscraper = matchscraper:__main__',
'matchscraper = matchscraper.main:main',
],
},
)

0 comments on commit eeddc29

Please sign in to comment.