Skip to content

Commit

Permalink
Merge pull request #34 from exislow/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
exislow authored Sep 11, 2022
2 parents 70ef832 + 58d59ba commit 9786b63
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kleinanzeigen-magic",
"version": "0.7.0",
"version": "0.8.0",
"description": "Speed up your Kleinanzeigen workflows!",
"productName": "Kleinanzeigen Magic",
"author": "Robert Honz <exislow gmail-com>",
Expand Down
17 changes: 16 additions & 1 deletion src-electron/main-process/kleinanzeigen-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export const adTopUp = async (id, price, title) => {
const regexContactName = /<ad:contact-name>.*<\/ad:contact-name>/;
const regexAttr = /<attr:attributes>.*<\/attr:attributes>/;
const regexShipping = /<ns6:shipping-options>.*<\/ns6:shipping-options>/;
const regexImprint = /<ad:imprint>.*<\/ad:imprint>/;
const regexPhone = /<ad:phone>.*<\/ad:phone>/;
let ad = null;
let xmlPictures = '';

Expand All @@ -129,7 +131,7 @@ export const adTopUp = async (id, price, title) => {
let adTitle = adXmlPrice.match(regexTitle);
adXmlPost += adTitle;
adXmlPost += adXmlPrice.match(regexTitle);
// Weird library behavior: Until proper decode you need to decode the string twice.
// Weird library behavior: To decode properly you need to decode the string twice.
let adXmlDescTmp = adXmlPrice.match(regexDesc)[1];
let adXmlDescTmpDec = he.decode(adXmlDescTmp);
let adXmlDescTmpDecDec = he.decode(adXmlDescTmpDec);
Expand All @@ -142,6 +144,19 @@ export const adTopUp = async (id, price, title) => {
adXmlPost += adXmlPrice.match(regexContactName);
adXmlPost += adXmlPrice.match(regexShipping);
adXmlPost += adXmlPrice.match(regexAttr);

// Check if imprint stuff is available
const resImprint = adXmlPrice.match(regexImprint);
const resPhone = adXmlPrice.match(regexPhone);

if (resImprint) {
adXmlPost += resImprint;
}

if (resPhone) {
adXmlPost += resPhone;
}

adXmlPost += xmlPictures;
adXmlPost += '</ad:ad>';

Expand Down
51 changes: 49 additions & 2 deletions src/pages/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
q-btn-group(spread)
q-btn(@click="openExternal('https://www.ebay-kleinanzeigen.de/')", icon="language", label="Kleinanzeigen Portal")
q-btn(@click="getAds()", icon="refresh", label="Anzeigen")
.row.q-gutter-y-sm
.col
q-banner.bg-red.text-black
template(v-slot:avatar)
q-icon(name="announcement")
| This app is still a BETA. Please note that bugs may occur which may result in unrecoverable or incorrect displayed ads.
| Use it at your own risk!
.row.q-gutter-y-sm(v-if="!allowTopUp")
.col
q-banner.bg-orange.text-black
template(v-slot:avatar)
q-icon(name="warning")
| You have created / topped-up more then {{ checkAllowTopUpMaxAds }} ads in the past {{ checkAllowTopUpDays }} days.
| According to Kleinanzeigen you are not allowed to create more than {{ checkAllowTopUpMaxAds + 1 }} ads in this time period.
| The top-up function is therefore suspended until you fall below the limit value again.
.row.q-pa-md.q-gutter-y-sm(v-if="!adsLoading", v-for="ad in ads", :key="ad.id")
.col-12
q-card
Expand Down Expand Up @@ -39,7 +54,7 @@
q-btn-group(outline)
q-btn(flat, :icon="ad['ad-status'].value == 'ACTIVE' ? 'public_off' : 'public'", @click="adPauseResume(ad['ad-status'].value == 'ACTIVE' ? 'pause' : 'resume', ad.id)")
q-tooltip Anzeige deaktivieren.
q-btn(outline, color="green", @click="dialogTopUpShow(ad)")
q-btn(outline, color="green", @click="dialogTopUpShow(ad)", :disable="!allowTopUp")
q-icon.rotate-270(name="double_arrow")
q-tooltip Anzeige gratis nach oben schieben.
q-btn(flat, color="red", icon="delete_forever", @click="dialogDeleteShow(ad)")
Expand Down Expand Up @@ -106,13 +121,20 @@ export default {
title: null,
editable: true
},
adsLoading: false
adsLoading: false,
allowTopUp: true,
checkAllowTopUpDays: 30,
checkAllowTopUpMaxAds: 49,
dayInMs: 86400000
};
},
mounted: function () {
this.$q.electron.ipcRenderer.on('m-get-ads', (event, arg) => {
this.ads = arg;
this.checkAllowTopUp();
this.adsLoading = false;
});
Expand Down Expand Up @@ -254,6 +276,31 @@ export default {
this.$q.loading.show({
message: 'Ich tue mein Bestes! Bitte warten...'
});
},
checkAllowTopUp: function () {
const adsInTimeScope = this.countNewAdsInPastDays(this.ads, this.checkAllowTopUpDays);
if (adsInTimeScope > this.checkAllowTopUpMaxAds) {
this.allowTopUp = false;
} else {
this.allowTopUp = true
}
},
countNewAdsInPastDays: function (ads, daysMax) {
const now = new Date();
let adsInTimeScope = 0;
for (let adItem of ads) {
const then = new Date(adItem['start-date-time']['value']);
const msBetweenDates = Math.abs(then.getTime() - now.getTime());
const daysBetweenDates = msBetweenDates / this.dayInMs;
if (daysBetweenDates < 30) {
adsInTimeScope++;
}
}
return adsInTimeScope;
}
}
};
Expand Down

0 comments on commit 9786b63

Please sign in to comment.