Skip to content

Commit

Permalink
Updated to version 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeCRamos committed Dec 4, 2018
1 parent 462de6e commit a18741f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ your computer, and the following dependencies:
+ `json`
+ `datetime`
+ `sys`
+ `threadings`

## Execution
First, you'll prepare the ambient with `make`. Then, to execute, just open the
project folder on your favorite terminal and type:
```bash
python3 pcalc [file-with-links] [kabum/mercadolivre]
python3 pcalc [file-with-links] [fetcher]
# file-with-links = A simple txt file containing one link per line.
# kabum/mercadolivre = The fetcher that you will use (at the moment, only these)
# fetcher = The fetcher that you will use
```

### Available Fetchers
+ [`mercadolivre`](https://www.mercadolivre.com.br)
+ [`kabum`](https://www.kabum.com.br)

*Have one? feel free to make a pull request with it!*

### Use examples
Let's say i have a file on `configs/test.txt`, and inside of it, i have:
```
Expand All @@ -36,7 +44,7 @@ I could run the program by typing the following commands:
I've designed this script to be as modular as you want. So with that in mind,
just need some little coding to make this script adapt to your desired website.

You'll need basic knowledge in `regex` and `python` in order to create your own
You'll need basic knowledge in `re`(regex) and `python` in order to create your own
API.

With that in mind, follow these steps:
Expand Down Expand Up @@ -81,5 +89,5 @@ Developed by Felipe Ramos under the **MIT License**.

##### Stats
```
version 0.2.1
version 0.2.2
```
45 changes: 17 additions & 28 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Price Fetcher
# A simple log generator for getting current prices on specified products.
# Author: FelipeCRamos
# Version: 0.2.1
# Version: 0.2.2

from product import Product

Expand All @@ -18,10 +18,10 @@
products = []

class FetchUrl(threading.Thread):
'''
Threads system, will fetch data from site and store-it on the data dict
'''
def run(self):
'''
Threads system, will fetch data from site and store-it on the data dict
'''

global data # Where the data will be inserted
global products # product list
Expand All @@ -34,7 +34,7 @@ def run(self):
# print("@thread: {} fetchind data...".format(threading.active_count()))
data[prod_name] = prod_price

pattern_pc_name = re.compile(r'/(.+)\.\w+')
pattern_pc_name = re.compile(r'/(.+)\.\w+') # re to get the path/<filename>.ext

def main():

Expand All @@ -45,7 +45,7 @@ def main():
products = [ line for line in input_f.read().split('\n') if line != '' ]


print("Fetchind data... Please wait.")
print("STATUS: Fetchind data... Please wait.")
for i in range(len(products)):
new_thread = FetchUrl(name = "Thread@{}".format(i+1))
new_thread.start()
Expand All @@ -54,34 +54,23 @@ def main():
while( threading.active_count() != 1 ):
continue

print("\nAll threads had finished!")
print("\nSTATUS: Fetching complete, now let's get the results!")
print("-" * 80)

total_price = 0
global data

for key in data:
total_price += data[key]
print("R$ {:10.2f}\t{}".format(data[key], key))

# for product in products:
# new_thread = FetchUrl(name = "Thread-")

# new_thread.start()
# curr = Product(product, input_site)
# prod_price = float(curr.getPrice())
# prod_name = curr.getName()

# print("R$ {:>10.2f}\t{}".format(prod_price, prod_name))

# total_price += prod_price
# data[prod_name] = prod_price
# exibit and calculate the sum of all prices
price_sum = 0
for item in data:
price_sum += data[item]
print("R$ {:10.2f}\t{}".format(data[item], item))

print("-" * 80)
print("R$ {:>10.2f}\tTOTAL".format(total_price))
print("R$ {:>10.2f}\tTOTAL W/ CARD TAX (15% +/-)".format(total_price * 1.15))
print("R$ {:>10.2f}\tTOTAL".format(price_sum))
print("R$ {:>10.2f}\tTOTAL W/ CARD TAX (15% +/-)".format(price_sum * 1.15))

data["TOTAL"] = total_price
data["TOTAL W/ TAXES (15%)"] = total_price * 1.15
data["TOTAL"] = price_sum
data["TOTAL W/ TAXES (15%)"] = price_sum * 1.15

# write on the output file

Expand Down

0 comments on commit a18741f

Please sign in to comment.