Styleguide/Scripts: Difference between revisions

Content deleted Content added
Cbarr (talk | contribs)
No edit summary
Cbarr (talk | contribs)
 
(4 intermediate revisions by the same user not shown)
Line 1:
==Introduction==
=="Form-countryspecific-*" creating scriptcode==
<syntaxhighlight lang="python">
import wikipedia
Line 707:
</syntaxhighlight>
 
=="Form-countryspecific-*" Mining scriptcode==
<syntaxhighlight lang="python">
import wikipedia
Line 937:
finally:
wikipedia.stopme()
</syntaxhighlight>
 
==Google currency conversion mining code==
<syntaxhighlight lang="cpp">
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
 
using namespace std;
 
long calculateDigits(double d)
{
long result = 0;
long temp = d;
long place = 1;
 
while(temp/place)
{
place *= 10;
result++;
}
return(result);
}
 
int main()
{
string website = "http://www.google.com/finance/";
string file = "converter?a=1&from=USD&to=";
string currency;
 
ofstream out;
ifstream currencyFile;
 
out.open("Google/ratesGoogle.txt");
currencyFile.open("currencyCodesAll.txt");
 
while(currencyFile >> currency)
{
string command = "wget '" + website + file + currency
+ "' && grep 'currency_converter_result' '"
+ file + currency + "' > 'resultGoogle.grep'";
 
system(command.c_str());
ifstream in("resultGoogle.grep");
string result;
 
getline(in,result,'\n');
 
in.close();
 
system("rm resultGoogle.grep");
 
result.erase(0,58);
 
bool remove = false;
for(long i = 0 ; i < result.size() ; i++)
{
if(result[i] == ' ')
remove = true;
if(remove)
result[i] = ' ';
}
 
if(result != "")
out << currency << " " << result << endl;
}
system("rm conv*");
out.close();
currencyFile.close();
 
vector<string> currencyList;
vector<double> rateList;
 
double rate;
 
ifstream in("Google/ratesGoogle.txt");
 
while(in >> currency && in >> rate)
{
rate = ceil(rate*100)/100.0;
currencyList.push_back(currency);
rateList.push_back(rate);
}
 
in.close();
 
unsigned options[16] = {1,2,3,5,10,15,20,25,30,35,50,75,100,150,200,250};
 
vector <vector <double> > currencyOptions;
currencyOptions.resize(rateList.size());
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
currencyOptions[i].resize(16);
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
currencyOptions[i][j] = rateList[i]*options[j];
}
}
 
// ===================== raw table ==============================
out.open("Google/currencyOptionsRawGoogle.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 16 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << currencyOptions[i][j] << ", ";
}
out << endl;
}
 
out.close();
 
// ================== rounded to nearest dollar ====================
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
for(long j=0 ; j < currencyOptions[i].size() ; j++)
currencyOptions[i][j] = ceil(currencyOptions[i][j]);
 
out.open("Google/currencyOptionsRoundedGoogle.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 16 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << ", ";
}
out << endl;
}
 
out.close();
 
// =================== zero bottom 1% digits =========================
double temp;
long digits;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
temp = currencyOptions[i][j];
digits = calculateDigits(temp);
 
if(digits < 3)
{}
else
{
temp /= (long)(pow(10,digits-3));
temp = ceil(temp);
temp *= (long)(pow(10,digits-3));
currencyOptions[i][j] = (long)temp;
}
}
 
out.open("Google/currencyOptionsZeroBottomGoogle.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 16 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << ", ";
}
out << endl;
}
 
out.close();
 
// =================== zero bottom 1% digits 5-ify =========================
 
long ones;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
temp = currencyOptions[i][j];
digits = calculateDigits(temp);
 
if(digits == 1)
{
//temp /= 5;
//temp = round(temp);
//temp *= 5;
//currencyOptions[i][j] = temp;
}
else
{
if(digits > 3)
temp /= (long)(pow(10,digits-3));
 
ones = (long)(temp)%10;
temp = temp - ones;
if(ones > 0 and ones <= 5)
{
temp += 5;
}
else if(ones > 6 and ones <= 9)
{
temp += 10;
}
if(digits > 3)
temp *= (long)(pow(10,digits-3));
 
currencyOptions[i][j] = (long)temp;
}
}
 
out.open("Google/currencyOptions5ifyGoogle.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 16 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << ", ";
}
out << endl;
}
 
out.close();
 
return 0;
}
 
</syntaxhighlight>
 
==Bloomberg currency conversion mining code==
<syntaxhighlight lang="cpp">
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
 
using namespace std;
 
long calculateDigits(double d)
{
long result = 0;
long temp = d;
long place = 1;
 
while(temp/place)
{
place *= 10;
result++;
}
return(result);
}
 
int main()
{
string website = "http://www.bloomberg.com/personal-finance/calculators/currency-converter/";
string currency;
 
ofstream out;
 
out.open("Bloomberg/ratesBloomberg.txt");
 
string command = "wget '" + website
+ "' && grep \":CUR\'\" 'index.html' > 'resultBloomberg.grep'";
system(command.c_str());
 
ifstream in("resultBloomberg.grep");
string result;
 
while(getline(in,result,'\n'))
{
 
string tempString;
 
result.erase(0,23);
tempString = result.substr(0,3);
result.erase(0,12);
result.erase(result.end()-1,result.end());
 
if(result != "")
out << tempString << " " << result << endl;
}
 
in.close();
system("rm resultBloomberg.grep");
system("rm inde*");
out.close();
 
vector<string> currencyList;
vector<double> rateList;
 
double rate;
 
in.open("Bloomberg/ratesBloomberg.txt");
 
while(in >> currency && in >> rate)
{
rate = ceil(rate*100)/100.0;
currencyList.push_back(currency);
rateList.push_back(rate);
}
 
in.close();
 
unsigned options[17] = {1,2,3,5,10,15,20,25,30,35,50,75,100,150,200,250,29500000};
 
vector <vector <double> > currencyOptions;
currencyOptions.resize(rateList.size());
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
currencyOptions[i].resize(17);
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
currencyOptions[i][j] = rateList[i]*options[j];
}
}
 
// ===================== raw table ==============================
out.open("Bloomberg/currencyOptionsRawBloomberg.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 17 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << currencyOptions[i][j] << ", ";
}
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << " ";
}
out << endl;
}
 
out.close();
 
// ================== rounded to nearest dollar ====================
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
for(long j=0 ; j < currencyOptions[i].size() ; j++)
currencyOptions[i][j] = ceil(currencyOptions[i][j]);
 
out.open("Bloomberg/currencyOptionsRoundedBloomberg.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 17 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << ", ";
}
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << " ";
}
out << endl;
}
 
out.close();
 
// =================== zero bottom 1% digits =========================
double temp;
long digits;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
temp = currencyOptions[i][j];
digits = calculateDigits(temp);
 
if(digits < 4)
{}
else
{
temp /= (long)(pow(10,digits-3));
temp = ceil(temp);
temp *= (long)(pow(10,digits-3));
currencyOptions[i][j] = (long)temp;
}
}
 
out.open("Bloomberg/currencyOptionsZeroBottomBloomberg.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 17 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << ", ";
}
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << " ";
}
out << endl;
}
 
out.close();
 
// =================== zero bottom 1% digits 5-ify =========================
long ones;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
temp = currencyOptions[i][j];
digits = calculateDigits(temp);
 
if(digits == 1)
{
//temp /= 5;
//temp = round(temp);
//temp *= 5;
//currencyOptions[i][j] = temp;
}
else
{
if(digits > 3)
temp /= (long)(pow(10,digits-3));
 
ones = (long)(temp)%10;
temp = temp - ones;
if(ones > 0 and ones <= 5)
{
temp += 5;
}
else if(ones >= 6 and ones <= 9)
{
temp += 10;
}
if(digits > 3)
temp *= (long)(pow(10,digits-3));
 
currencyOptions[i][j] = (long)temp;
}
}
 
out.open("Bloomberg/currencyOptions5ifyBloomberg.csv");
 
out << "USD, rate,";
for(long j=0 ; j < 17 ; j++)
{
out << options[j] << ", ";
}
out << endl;
 
for(long i = 0 ; i < currencyOptions.size() ; i++)
{
out << currencyList[i] << ", " << rateList[i] << ", ";
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << ", ";
}
 
for(long j=0 ; j < currencyOptions[i].size() ; j++)
{
out << (long)currencyOptions[i][j] << " ";
}
out << ", ";
 
out << "\"" << (long)currencyOptions[i][3] << " "
<< (long)currencyOptions[i][4] << " "
<< (long)currencyOptions[i][6] << " "
<< (long)currencyOptions[i][9] << " "
<< (long)currencyOptions[i][10] << " "
<< (long)currencyOptions[i][12] << " "
<< (long)currencyOptions[i][15] << "\"" << endl;
}
 
out.close();
 
return 0;
}
 
</syntaxhighlight>