Skip to content

Commit 06a8359

Browse files
authored
0.3.2
0.3.2
2 parents 59110a0 + 628e905 commit 06a8359

File tree

14 files changed

+166
-25
lines changed

14 files changed

+166
-25
lines changed

CHANGELOG.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
# Changelog
22

3-
## 0.3.1 (2023-07-15) #42
3+
## 0.3.2 (2023-07-17) [#44](https://github.com/TuTarea/vinted-rs/pull/44/)
4+
5+
## Added
6+
7+
- Models now implement serde::{Serialize, Deserialize} [#43](https://github.com/TuTarea/vinted-rs/pull/43/)
8+
9+
## Improved
10+
11+
- Example project, python benchmark added [#41](https://github.com/TuTarea/vinted-rs/pull/41/)
12+
13+
## 0.3.1 (2023-07-15) [#42](https://github.com/TuTarea/vinted-rs/pull/42/)
414

515
### Fixed
616

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

1020
### Improved
1121

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

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

1626
### Added
1727

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

2232
### Improved
2333

24-
- Documentation for `filter` module - #35
34+
- Documentation for `filter` module - [#35]((https://github.com/TuTarea/vinted-rs/pull/35/))

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vinted-rs"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition = "2021"
55
repository = "https://github.com/TuTarea/vinted-rs"
66
authors = ["Pepe Márquez <pepe.marquezromero@gmail.com>" , "Álvaro Cabo <alvarocaboac2@gmail.com>"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Via `cargo` you can add the library to your project's `Cargo.toml`
2424

2525
```toml
2626
[dependencies]
27-
vinted-rs = "0.3.1"
27+
vinted-rs = "0.3.2"
2828
```
2929

3030
## DB setup

examples/filter_example/benchmark.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""
2+
CookieErrors Benchmark Script
3+
4+
This script benchmarks the amount of CookieErrors obtained when running the main.rs example.
5+
6+
The script runs the main.rs example multiple times for each host, capturing the number of
7+
GetCookiesError occurrences. It then generates a bar chart to visualize the error counts.
8+
9+
*Discalimer:* Because this file is intended for internal debug, it is certainly not the most
10+
efficient implementation and it is not tested at all
11+
12+
"""
13+
import os, sys
14+
import subprocess
15+
from enum import Enum
16+
import matplotlib.pyplot as plt
17+
from matplotlib.ticker import MultipleLocator
18+
from tqdm import tqdm
19+
20+
class Host(Enum):
21+
Fr = "fr"
22+
Be = "be"
23+
Es = "es"
24+
Lu = "lu"
25+
Nl = "nl"
26+
Lt = "lt"
27+
De = "de"
28+
At = "at"
29+
It = "it"
30+
Uk = "co.uk"
31+
Pt = "pt"
32+
Com = "com"
33+
Cz = "cz"
34+
Sk = "sk"
35+
Pl = "pl"
36+
Se = "se"
37+
Ro = "ro"
38+
Hu = "hu"
39+
40+
# Check the number of command-line arguments
41+
if len(sys.argv) != 2:
42+
print("Invalid number of arguments. Usage: python benchmark.py <n>")
43+
sys.exit(1)
44+
45+
n = int(sys.argv[1])
46+
47+
# Define the binary command
48+
binary_command = "target/debug/filter_example"
49+
50+
# Initialize a dictionary to store the error counts
51+
ok_counts = {}
52+
53+
# Create the progress bar
54+
progress_bar = tqdm(Host, desc="Processing", unit="host")
55+
56+
# Run the binary for each host and capture the error counts
57+
for host in progress_bar:
58+
ok_count = n
59+
for _ in range(n):
60+
process = subprocess.run(
61+
[binary_command, host.value],
62+
capture_output=True,
63+
text=True
64+
)
65+
output = process.stderr.strip()
66+
ok_count -= output.count("GetCookiesError")
67+
68+
ok_counts[host.value] = ok_count
69+
progress_bar.set_postfix({"Host": host.value})
70+
71+
# Close the progress bar
72+
progress_bar.close()
73+
74+
# Prepare the data for plotting
75+
hosts = list(ok_counts.keys())
76+
errors = list(ok_counts.values())
77+
78+
# Set the style and color palette
79+
colors = plt.cm.Set3(range(len(hosts)))
80+
81+
# Create a figure with a larger size
82+
fig, ax = plt.subplots(figsize=(10, 6))
83+
84+
# Plot the chart
85+
bars = ax.bar(hosts, errors, color=colors)
86+
87+
# Customize the plot
88+
plt.xlabel("Host", fontsize=12)
89+
plt.ylabel("Error Count", fontsize=12)
90+
plt.title("200-OK status code received", fontsize=14)
91+
ax.yaxis.set_major_locator(MultipleLocator(1)) # Set y-axis tick frequency to 1
92+
ax.grid(axis="y", linestyle="--", alpha=0.5)
93+
94+
# Add data labels to the bars
95+
for bar in bars:
96+
height = bar.get_height()
97+
ax.annotate(f"{height}", xy=(bar.get_x() + bar.get_width() / 2, height),
98+
xytext=(0, 3), textcoords="offset points",
99+
ha="center", va="bottom")
100+
101+
# Create the "results" directory if it doesn't exist
102+
os.makedirs("results", exist_ok=True)
103+
104+
# Save the chart as a JPG file
105+
output_file = os.path.join("results", "chart.jpg")
106+
plt.savefig(output_file, dpi=300, bbox_inches="tight")
107+
print(f"Chart saved to {output_file}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
matplotlib==3.4.3
2+
tqdm==4.62.3

examples/filter_example/src/main.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
use bb8_postgres::tokio_postgres::NoTls;
2-
use vinted_rs::{db::DbController, Filter, VintedWrapper , queries::Host};
2+
3+
use std::env;
4+
use vinted_rs::{db::DbController, queries::Host, Filter, VintedWrapper};
5+
36

47
#[tokio::main]
58
async fn main() {
9+
let args: Vec<String> = env::args().collect();
10+
11+
if args.len() < 2 {
12+
println!("Please provide the host as a command-line parameter.");
13+
return;
14+
}
15+
16+
let host_arg = args[1].as_str();
17+
let host: Host = host_arg.into();
18+
619
let db = DbController::new("postgres://postgres:postgres@localhost/vinted-rs", 5, NoTls)
720
.await
821
.unwrap();
@@ -18,14 +31,15 @@ async fn main() {
1831
.price_to(20)
1932
.build();
2033

21-
let vinted = VintedWrapper::new_with_host(Host::Uk);
34+
let vinted = VintedWrapper::new_with_host(host);
2235

23-
println!("Host : {}" , vinted.get_host());
36+
println!("Host: {}", vinted.get_host());
2437

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

27-
if items.items.len() <= 0 {
40+
if items.items.is_empty() {
41+
2842
println!("No items found");
2943
}
3044
println!("{}", items);
31-
}
45+
}

src/model/filter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use serde::{Deserialize, Serialize};
12
use typed_builder::TypedBuilder;
23

34
use crate::queries::Host;
@@ -43,7 +44,7 @@ pub mod size;
4344
///
4445
/// `price_from` filter should be always <= `price_to` , otherwise Vinted will not find anything
4546
///
46-
#[derive(TypedBuilder, Debug, Clone)]
47+
#[derive(TypedBuilder, Debug, Clone, Serialize, Deserialize)]
4748
pub struct Filter {
4849
///The search text to filter items by.
4950
///### Example
@@ -299,7 +300,7 @@ impl From<Currency> for &str {
299300
Represents the article status for filtering items.
300301
301302
*/
302-
#[derive(Debug, Clone)]
303+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
303304
pub enum ArticleStatus {
304305
/// The article status for new items with tags.
305306
NewTags,
@@ -329,7 +330,7 @@ impl From<&ArticleStatus> for &str {
329330
Represents the sort order for the retrieved items.
330331
*/
331332

332-
#[derive(Debug, Clone)]
333+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
333334
pub enum SortBy {
334335
/// Sort items by relevance.
335336
Relevance,

src/model/filter/brand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

5-
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
6+
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
67
pub struct Brand {
78
/// Brand id given by Vinted
89
pub id: i32,

src/model/filter/category.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

5-
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
6+
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
67
pub struct Category {
78
/// Category id given by Vinted
89
pub id: i32,

src/model/filter/category_tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

5-
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
6+
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
67
pub struct CategoryTree {
78
/// Vinted-rs autogenerated id
89
pub id: i32,

src/model/filter/colors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

5-
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
6+
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
67
pub struct Color {
78
/// Color id given by Vinted
89
pub id: i32,

src/model/filter/country.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

5-
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
6+
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
67
pub struct Country {
78
/// Country id given by Vinted
89
pub id: i32,

src/model/filter/material.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

5-
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq)]
6+
#[derive(Debug, Clone, TypedBuilder, PartialEq, Eq, Serialize, Deserialize)]
67
pub struct Material {
78
/// Material id given by Vinted
89
pub id: i32,

src/model/filter/size.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#[cfg(feature = "advanced_filters")]
22
use bb8_postgres::tokio_postgres::Row;
3+
use serde::{Deserialize, Serialize};
34
use typed_builder::TypedBuilder;
45

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

0 commit comments

Comments
 (0)