Skip to content

Commit

Permalink
0.3.2
Browse files Browse the repository at this point in the history
0.3.2
  • Loading branch information
0xCAB0 authored Jul 17, 2023
2 parents 59110a0 + 628e905 commit 06a8359
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 25 deletions.
26 changes: 18 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
# Changelog

## 0.3.1 (2023-07-15) #42
## 0.3.2 (2023-07-17) [#44](https://github.com/TuTarea/vinted-rs/pull/44/)

## Added

- Models now implement serde::{Serialize, Deserialize} [#43](https://github.com/TuTarea/vinted-rs/pull/43/)

## Improved

- Example project, python benchmark added [#41](https://github.com/TuTarea/vinted-rs/pull/41/)

## 0.3.1 (2023-07-15) [#42](https://github.com/TuTarea/vinted-rs/pull/42/)

### Fixed

- UK host had wrong domain #38
- Not using user-agent resulted in some domains returning 403 #38
- UK host had wrong domain [#38](https://github.com/TuTarea/vinted-rs/pull/38/)
- Not using user-agent resulted in some domains returning 403 [#38](https://github.com/TuTarea/vinted-rs/pull/38/)

### Improved

- CookieError now returns the Status Code of the requests
- CookieError now returns the Status Code of the requests [#38](https://github.com/TuTarea/vinted-rs/pull/38/)

## 0.3.0 (2023-07-15) #34
## 0.3.0 (2023-07-15) [#34]((https://github.com/TuTarea/vinted-rs/pull/34/))

### Added

- Filter by Currency implemented - #32
- Example project using advanced filters feature - #33
- Filter by Currency implemented - [#32](https://github.com/TuTarea/vinted-rs/pull/32/)
- Example project using advanced filters feature - [#33]((https://github.com/TuTarea/vinted-rs/pull/33/))
- CHANGELOG file

### Improved

- Documentation for `filter` module - #35
- Documentation for `filter` module - [#35]((https://github.com/TuTarea/vinted-rs/pull/35/))
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vinted-rs"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
repository = "https://github.com/TuTarea/vinted-rs"
authors = ["Pepe Márquez <[email protected]>" , "Álvaro Cabo <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Via `cargo` you can add the library to your project's `Cargo.toml`

```toml
[dependencies]
vinted-rs = "0.3.1"
vinted-rs = "0.3.2"
```

## DB setup
Expand Down
107 changes: 107 additions & 0 deletions examples/filter_example/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
CookieErrors Benchmark Script
This script benchmarks the amount of CookieErrors obtained when running the main.rs example.
The script runs the main.rs example multiple times for each host, capturing the number of
GetCookiesError occurrences. It then generates a bar chart to visualize the error counts.
*Discalimer:* Because this file is intended for internal debug, it is certainly not the most
efficient implementation and it is not tested at all
"""
import os, sys
import subprocess
from enum import Enum
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
from tqdm import tqdm

class Host(Enum):
Fr = "fr"
Be = "be"
Es = "es"
Lu = "lu"
Nl = "nl"
Lt = "lt"
De = "de"
At = "at"
It = "it"
Uk = "co.uk"
Pt = "pt"
Com = "com"
Cz = "cz"
Sk = "sk"
Pl = "pl"
Se = "se"
Ro = "ro"
Hu = "hu"

# Check the number of command-line arguments
if len(sys.argv) != 2:
print("Invalid number of arguments. Usage: python benchmark.py <n>")
sys.exit(1)

n = int(sys.argv[1])

# Define the binary command
binary_command = "target/debug/filter_example"

# Initialize a dictionary to store the error counts
ok_counts = {}

# Create the progress bar
progress_bar = tqdm(Host, desc="Processing", unit="host")

# Run the binary for each host and capture the error counts
for host in progress_bar:
ok_count = n
for _ in range(n):
process = subprocess.run(
[binary_command, host.value],
capture_output=True,
text=True
)
output = process.stderr.strip()
ok_count -= output.count("GetCookiesError")

ok_counts[host.value] = ok_count
progress_bar.set_postfix({"Host": host.value})

# Close the progress bar
progress_bar.close()

# Prepare the data for plotting
hosts = list(ok_counts.keys())
errors = list(ok_counts.values())

# Set the style and color palette
colors = plt.cm.Set3(range(len(hosts)))

# Create a figure with a larger size
fig, ax = plt.subplots(figsize=(10, 6))

# Plot the chart
bars = ax.bar(hosts, errors, color=colors)

# Customize the plot
plt.xlabel("Host", fontsize=12)
plt.ylabel("Error Count", fontsize=12)
plt.title("200-OK status code received", fontsize=14)
ax.yaxis.set_major_locator(MultipleLocator(1)) # Set y-axis tick frequency to 1
ax.grid(axis="y", linestyle="--", alpha=0.5)

# Add data labels to the bars
for bar in bars:
height = bar.get_height()
ax.annotate(f"{height}", xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3), textcoords="offset points",
ha="center", va="bottom")

# Create the "results" directory if it doesn't exist
os.makedirs("results", exist_ok=True)

# Save the chart as a JPG file
output_file = os.path.join("results", "chart.jpg")
plt.savefig(output_file, dpi=300, bbox_inches="tight")
print(f"Chart saved to {output_file}")
2 changes: 2 additions & 0 deletions examples/filter_example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
matplotlib==3.4.3
tqdm==4.62.3
24 changes: 19 additions & 5 deletions examples/filter_example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
use bb8_postgres::tokio_postgres::NoTls;
use vinted_rs::{db::DbController, Filter, VintedWrapper , queries::Host};

use std::env;
use vinted_rs::{db::DbController, queries::Host, Filter, VintedWrapper};


#[tokio::main]
async fn main() {
let args: Vec<String> = env::args().collect();

if args.len() < 2 {
println!("Please provide the host as a command-line parameter.");
return;
}

let host_arg = args[1].as_str();
let host: Host = host_arg.into();

let db = DbController::new("postgres://postgres:postgres@localhost/vinted-rs", 5, NoTls)
.await
.unwrap();
Expand All @@ -18,14 +31,15 @@ async fn main() {
.price_to(20)
.build();

let vinted = VintedWrapper::new_with_host(Host::Uk);
let vinted = VintedWrapper::new_with_host(host);

println!("Host : {}" , vinted.get_host());
println!("Host: {}", vinted.get_host());

let items = vinted.get_items(&filter, 10).await.unwrap();

if items.items.len() <= 0 {
if items.items.is_empty() {

println!("No items found");
}
println!("{}", items);
}
}
7 changes: 4 additions & 3 deletions src/model/filter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use crate::queries::Host;
Expand Down Expand Up @@ -43,7 +44,7 @@ pub mod size;
///
/// `price_from` filter should be always <= `price_to` , otherwise Vinted will not find anything
///
#[derive(TypedBuilder, Debug, Clone)]
#[derive(TypedBuilder, Debug, Clone, Serialize, Deserialize)]
pub struct Filter {
///The search text to filter items by.
///### Example
Expand Down Expand Up @@ -299,7 +300,7 @@ impl From<Currency> for &str {
Represents the article status for filtering items.
*/
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ArticleStatus {
/// The article status for new items with tags.
NewTags,
Expand Down Expand Up @@ -329,7 +330,7 @@ impl From<&ArticleStatus> for &str {
Represents the sort order for the retrieved items.
*/

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum SortBy {
/// Sort items by relevance.
Relevance,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/brand.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct Brand {
/// Brand id given by Vinted
pub id: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/category.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct Category {
/// Category id given by Vinted
pub id: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/category_tree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct CategoryTree {
/// Vinted-rs autogenerated id
pub id: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/colors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct Color {
/// Color id given by Vinted
pub id: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/country.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct Country {
/// Country id given by Vinted
pub id: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/material.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct Material {
/// Material id given by Vinted
pub id: i32,
Expand Down
3 changes: 2 additions & 1 deletion src/model/filter/size.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#[cfg(feature = "advanced_filters")]
use bb8_postgres::tokio_postgres::Row;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

// TODO las tallas y las categorias de tallas están solo en Castellano
/**
Size structs are differenciated by parent categories
XL for Men is not the same as XL for children
*/
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
pub struct Size {
/// Vinted-rs autogenerated id
pub id: i32,
Expand Down

0 comments on commit 06a8359

Please sign in to comment.