Skip to content

Instantly share code, notes, and snippets.

@mejje
Created January 5, 2019 10:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mejje/a783c569fd4203d13cfa62e399f9fa36 to your computer and use it in GitHub Desktop.
TraderaPush
#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; }
}
@mejje
Copy link
Author

mejje commented Jan 5, 2019

function.json

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */10 5-21 * * *"
    },
    {
      "type": "table",
      "name": "inputTable",
      "tableName": "traderaItems",
      "take": 50,
      "connection": "AzureWebJobsDashboard",
      "direction": "in"
    },
    {
      "type": "table",
      "name": "outputTable",
      "tableName": "traderaItems",
      "connection": "AzureWebJobsDashboard",
      "direction": "out"
    }
  ],
  "disabled": false
}

@jimmystridh
Copy link

ChatGPT explains this as:

This C# code is a script that runs on Azure Functions. It appears to use the Tradera API to search for items in a specific category that have a "Buy It Now" option. The search results are then filtered to include only auctions with the "Buy It Now" option, and then for each item returned, the code checks if it is already in an Azure Table storage. If the item is not found in the table, it is added and a message is sent using the Pushover service with the item's description, buy it now price and URL.

It requires additional assembly references including:

System.Net
System.ServiceModel
Microsoft.WindowsAzure.Storage
TraderaClient.dll which seems to be a custom assembly made by developer.
It also specifies that it needs some keys or secrets to be entered (appServiceKey, pushoverToken, pushoverKey) those are specified as "GET_FROM_xxx".

@jimmystridh
Copy link

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:

  • An Azure account with an Azure Function app set up
  • A Tradera account
  • A Pushover account

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 account
  • appServiceKey: The Tradera App Service Key associated with your account
  • categoryId: The category ID you wish to search for
  • pushoverToken: Your Pushover API token
  • pushoverKey: Your Pushover user key

Usage

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment