Created
January 5, 2019 10:42
-
-
Save mejje/a783c569fd4203d13cfa62e399f9fa36 to your computer and use it in GitHub Desktop.
TraderaPush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "System.Net" | |
#r "System.ServiceModel" | |
#r "Microsoft.WindowsAzure.Storage" | |
#r "TraderaClient.dll" | |
using System; | |
using System.Collections.Specialized; | |
using System.Net; | |
using System.ServiceModel; | |
using Microsoft.WindowsAzure.Storage.Table; | |
using TraderaClient.SearchService; | |
public static void Run( | |
TimerInfo myTimer, | |
IQueryable<TraderaItem> inputTable, | |
ICollector<TraderaItem> outputTable, | |
TraceWriter log) | |
{ | |
const int appId = 1779; | |
const string appServiceKey = "GET_FROM_TRADERA"; | |
const int categoryId = 344671; // oneplus | |
//const int categoryId = 2601; // mobiltelefoner | |
const string pushoverToken = "GET_FROM_PUSHOVER"; | |
const string pushoverKey = "GET_FROM_PUSHOVER"; | |
var searchService = new SearchServiceSoapClient( | |
new BasicHttpBinding(), | |
new EndpointAddress("http://api.tradera.com/v3/SearchService.asmx")); | |
var result = searchService.SearchAdvanced(new AuthenticationHeader | |
{ | |
AppId = appId, | |
AppKey = appServiceKey | |
}, null, new SearchAdvancedRequest | |
{ | |
CategoryId = categoryId, | |
OnlyAuctionsWithBuyNow = true, | |
ItemType = "Auction", | |
SellerType = "Private", | |
OrderBy = "StartDateDescending" | |
}); | |
if (result.Errors != null && result.Errors.Length > 0) | |
throw new Exception(string.Join<Error>(Environment.NewLine, result.Errors)); | |
if (result.Items == null) | |
return; | |
var resultItems = result.Items | |
.Where(x => x.ItemType == "AuctionWithBuyItNow"); | |
foreach (var item in resultItems) | |
{ | |
var storedItem = inputTable.Where(x => | |
x.PartitionKey == categoryId.ToString() && | |
x.RowKey == item.Id.ToString()).SingleOrDefault(); | |
if (storedItem == null) | |
{ | |
outputTable.Add(new TraderaItem | |
{ | |
PartitionKey = categoryId.ToString(), | |
RowKey = item.Id.ToString(), | |
CategoryId = categoryId, | |
Id = item.Id, | |
ShortDescription = item.ShortDescription, | |
BuyItNowPrice = item.BuyItNowPrice | |
}); | |
using (var client = new WebClient()) | |
{ | |
client.UploadValues("https://api.pushover.net/1/messages.json", | |
new NameValueCollection { | |
{ "token", pushoverToken }, | |
{ "user", pushoverKey }, | |
{ "message", $"Buy it now for {item.BuyItNowPrice} kr" }, | |
{ "url", $"http://www.tradera.com/item/{categoryId}/{item.Id}/1" }, | |
{ "url_title", item.ShortDescription } | |
}); | |
} | |
} | |
} | |
} | |
public class TraderaItem : TableEntity | |
{ | |
public int CategoryId { get; set; } | |
public int Id { get; set; } | |
public string ShortDescription { get; set; } | |
public int? BuyItNowPrice { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tradera Auction Notifier
This C# script searches for Tradera auctions with a specific category ID and filters for auctions that have a Buy It Now price. When a new auction is found that matches the criteria, it is added to an Azure Table Storage and a push notification is sent using the Pushover API.
Getting Started
To run this script, you will need:
Once you have these set up, you will need to update the following variables in the script:
appId
: The Tradera App ID associated with your accountappServiceKey
: The Tradera App Service Key associated with your accountcategoryId
: The category ID you wish to search forpushoverToken
: Your Pushover API tokenpushoverKey
: Your Pushover user keyUsage
This script is designed to be run as an Azure Function on a timer trigger. The timer is set up in the Azure Function app and configured to run at a specific interval.
The script will search for Tradera auctions with a Buy It Now price in the specified category and add any new auctions found to an Azure Table Storage. If a new auction is found, a push notification will be sent using the Pushover API.
Contributing
This script was written as a proof of concept and is not intended for production use. However, if you wish to contribute to the script, feel free to submit a pull request.
License
This script is licensed under the MIT License.