Skip to content

Instantly share code, notes, and snippets.

@GrakovNe
Created August 9, 2018 08:51
Show Gist options
  • Select an option

  • Save GrakovNe/94bb57f356a5cdfb092fe1c99ab6072f to your computer and use it in GitHub Desktop.

Select an option

Save GrakovNe/94bb57f356a5cdfb092fe1c99ab6072f to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
public class Featcher {
public static void main(String[] args) throws IOException {
List<Integer> ids = asList(80428, 80429, 80430, 80431, 80443, 80444, 80432, 80433, 80445, 80447, 80446, 80434, 80435, 80436, 80438, 80437, 80439, 80448, 80449, 80450, 80440, 80441, 80442, 80001, 80468, 80470, 80471, 80472, 80473, 80474, 80475, 80476, 80477, 80469, 80479, 80480, 80478, 80481, 80482, 80206, 80097, 80099, 80013, 80014, 80093, 80015, 80016, 80054, 80017, 80018, 80019, 80020, 80021, 80022, 80023, 80024, 80025, 80026, 80080, 80081, 80057, 80027, 80028, 80059, 80029, 80030, 80060, 80031, 80032, 80061, 80034, 80035, 80036, 80038, 80693, 80039, 80094, 80063, 80041, 80064, 80694, 80042, 80047, 80043, 80044, 80171, 80049, 80311, 80111, 80172, 80112, 80102, 80173, 80113, 80103, 80174, 80170, 80110, 80175, 80114, 80104, 80176, 80115, 80105, 80177, 80116, 80012, 80178, 80117, 80106, 80179, 80118, 80079, 80180, 80119, 80006, 80181, 80120, 80004, 80182, 80190, 80050, 80187, 80127, 80051, 80188, 80128, 80068, 80183, 80121, 80107, 80184, 80122, 80108, 80185, 80123, 80109, 80186, 80124, 80052, 80189, 80129, 80169, 80067, 80065, 80069, 80070, 80308, 80309, 80316, 80317, 80312, 80314, 80318, 80319, 80310, 80315, 80320, 80321, 80313, 80546, 80552, 80551, 80554, 80555, 80556, 80553, 80463, 80517, 80529, 80518, 80519, 80520, 80530, 80535, 80534, 80536, 80537, 80531, 80538, 80539, 80540, 80541, 80532, 80542, 80543, 80544, 80521, 80522, 80533, 80523, 80524, 80526, 80193, 80195, 80200, 80201, 80194, 80197, 80198, 80199, 80196, 80207, 80210, 80220, 80221, 80222, 80209, 80208, 80223, 80224, 80244, 80245, 80246, 80247, 80213, 80286, 80211, 80592, 80226, 80227, 80228, 80232, 80233, 80285, 80235, 80229, 80230, 80231, 80412, 80413, 80425, 80414, 80415, 80416, 80417, 80418, 80419, 80424, 80420, 80426, 80421, 80422, 80423, 80593, 80597, 80595, 80596, 80598, 80599, 80600, 80601, 80602, 80603, 80130, 80132, 80142, 80409, 80135, 80140, 80138, 80141, 80410, 80136, 80411, 80153, 80152, 80139, 80192, 80133, 80150, 80151, 80134, 80143, 80144, 80191, 80145, 80146, 80149, 80137, 80464, 80507, 80508, 80503, 80509, 80510, 80511, 80504, 80512, 80513, 80505, 80506, 80515, 80516, 80404, 80237, 80483, 80484, 80485, 80486, 80487, 80488, 80490, 80491, 80492, 80493, 80494, 80496, 80497, 80498, 80499, 80500, 80238, 80260, 80258, 80262, 80259, 80265, 80274, 80272, 80273, 80261, 80257, 80239, 80255, 80256, 80275, 80254, 80240, 80250, 80251, 80502, 80249, 80248, 80252, 80241, 80268, 80266, 80267, 80270, 80269, 80271, 80242, 80501, 80264, 80253, 80263, 80243, 80131, 80204, 80161, 80158, 80403, 80205, 80155, 80160, 80159, 80157, 80203, 80167, 80165, 80202, 80166, 80164, 80276, 80277, 80278, 80279, 80280, 80283, 80284, 80281, 80282, 80545, 80548, 80559, 80560, 80561, 80549, 80562, 80563, 80550, 80569, 80576, 80303, 80304, 80305, 80306, 80287, 80288, 80393, 80397, 80398, 80604, 80289, 80405, 80406, 80407, 80408, 80290, 80291, 80396, 80399, 80400, 80401, 80402, 80465, 80605, 80606, 80695, 80619, 80626, 80698, 80613, 80624, 80615, 80616, 80712, 80611, 80715, 80614, 80617, 80620, 80628, 80618, 80621, 80623, 80625, 80627, 80722, 80612, 80629, 80622, 80607, 80630, 80634, 80730, 80641, 80736, 80632, 80635, 80636, 80637, 80747, 80643, 80640, 80642, 80766, 80631, 80639, 80633, 80644, 80781, 80638, 80608, 80790, 80649, 80650, 80645, 80647, 80648, 80646, 80610, 80819, 80671, 80688, 80689, 80822, 80656, 80657, 80658, 80828, 80668, 80676, 80683, 80684, 80659, 80660, 80661, 80662, 80663, 80833, 80664, 80669, 80677, 80687, 80665, 80666, 80667, 80670, 80672, 80673, 80674, 80675, 80678, 80679, 80680, 80681, 80682, 80685);
String collect = ids
.stream()
.map(id -> {
try {
String fileName = "out.sh";
System.out.println("fetching for: " + id);
String s = "curl 'https://adwords.google.com/aw_displayads/cons/_/rpc/ComixService/Query?authuser=0&rpcTrackingId=ComixService.Query%3A7' -H 'x-same-domain: 1' -H 'origin: https://adwords.google.com' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,da;q=0.6' -H 'cookie: CONSENT=YES+NL.ru+V9; adwordsReferralSource=sourceid=awo&subid=ru-ww-et-g-aw-a-tools-ma-awhp!o2&clickid=sn-5r-og-ru-04052018; OGPC=19006965-1:19007018-1:; OGP=-19006965:-19007018:; __utmz=229779660.1531131146.32.5.utmcsr=accounts.google.com|utmccn=(referral)|utmcmd=referral|utmcct=/ServiceLogin/signinchooser; __utma=229779660.2101621461.1523468861.1532880427.1533016354.43; AdsUserLocale=en_US; _ga=GA1.3.2101621461.1523468861; SID=VAbCMmxRhTiE1rJj3932C9CfRVMYMTzE1-fu16QTB4z8tkdI_oqrWjbQ3QaUC2qOknqvEA.; HSID=A1LbVU6v1yEaoS1Ml; SSID=AJ2F8K4oD4Yof2YHw; APISID=reE84_vrCgAY-UrK/AfjvgwhSWmQcv3J7g; SAPISID=YL9x_IGWXsI3nAG2/Ax-IMfUtkT10vmHtC; SAG=VAbCMh-ZaevaN1-I6KGHBcyBbuaVlezyWb6fO6q9OfUB0q5eIjgp0lQa5Dwa3FYVoSfdQA.; _gid=GA1.3.1133393659.1533548731; 1P_JAR=2018-8-9-7; NID=136=F5jE36ZdUr10xlelZnc90f1_SDCQVmzJ1NHXWyMepmtfH5UCzDT0ngtpfoj058DhiZAHU6Dm3mOzsJ9JOVQEVFPpkZxwCyA-YkbzR6tZmJdfRHaZO5wTd16pz2bKIu1-GfgBD-_kLBzvonvnkNoEBp0BHdqTwWz4dhN5CuYNfXvRstRKe4K40jRzzW5QLR_M0Koe8ELbMhkfnYxaVKT9l1plXbIH4PNTFbwkTdd-dEAyBGtZF_4vhrDGB-L8GdhKTQ; S=adwords-usermgmt=yFmgy4BH1yX7yYzU7Z5ObPAIvqdkJ3xh:adwords-frontend-reporting=PkGqrSqmavxItsBiZ2HmoJ-mnlib6kNf:adwords-navi=K-1SIEBoq_bYcLnTmYGsVRoJMxPfpj2I:adwords-frontend-displayads=cZMvoXfJ8aJ5BtX4WLOTbShaKx4tVVQk:adwords-frontend-mcc=yTse7_Opun_jObGIk_K0PCmxLDVGyTK_; A=AIxWtxTKtzlBr60MBPgg2lo7isK9DOlY4CjEUxsDSSaaZrz3p0x7DBpyvRzVEjROhZSYmNDK0GOd9oKnPWlXfs080HMwYX1LsWnbOpYMcD6m17fLGhw6j-YRVTPGqtvzgGF1mIiPVYYLqH1WhQpoxJjTmF-v8b6deEXSQxSKUyzT26b2JmdbIX7Q8CdfftUfiSBnPSNWp95b; SIDCC=AGIhQKTFzkkXblrlBavNeOPOwsgxAKHg4FM84V_M_ljVtjK6Fya24hV2xLG43scr1Ziq81eNrFM' -H 'x-client-data: CI62yQEIorbJAQjEtskBCKmdygEI153KAQioo8oBCIKkygEIkqfKAQ==' -H 'x-framework-xsrf-token: AAcSu3QWk7WorrI2ORfLsiHDuBp4FqyChw:1533800305673' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36' -H 'content-type: application/x-www-form-urlencoded' -H 'accept: */*' -H 'referer: https://adwords.google.com/aw/campaigns/new/display?channel=1&ocid=265684508&cmpnInfo=%7B%221%22%3A2%2C%228%22%3A%2205472D9E-9DBB-40F2-8CEB-2A5599F234F3--33%22%2C%2213%22%3A0%2C%2218%22%3A1%7D&__c=2729426015&authuser=0&__u=7759726148' -H 'authority: adwords.google.com' -H 'build-version: v1533255304' --data 'hl=en_US&__lu=276478052&__u=7759726148&__c=2729426015&f.sid=-5847745926022700000&__ar=%7B%221%22%3A%7B%221%22%3A%7B%221%22%3A%22265684508%22%2C%222%22%3A%22USD%22%2C%223%22%3A%2210800000%22%2C%224%22%3Afalse%7D%2C%222%22%3A%5B%7B%222%22%3A%5B%7B%222%22%3A%5B%7B%221%22%3A4%7D%5D%2C%223%22%3A%5B%7B%221%22%3A11%2C%223%22%3A%7B%222%22%3A%22" + id + "%22%7D%2C%224%22%3Afalse%7D%5D%2C%229%22%3A2%7D%5D%2C%223%22%3A%5B%7B%221%22%3A2%2C%222%22%3A%221000%22%7D%2C%7B%221%22%3A1%2C%222%22%3A%222643%22%2C%224%22%3Afalse%7D%5D%2C%225%22%3A5%2C%226%22%3A%7B%221%22%3A%22500000000%22%7D%2C%227%22%3A3%2C%2211%22%3Atrue%2C%2213%22%3A0%7D%5D%7D%2C%222%22%3Afalse%2C%223%22%3Afalse%2C%224%22%3Afalse%2C%225%22%3Afalse%2C%226%22%3Afalse%2C%227%22%3Afalse%2C%229%22%3Atrue%2C%2211%22%3Afalse%7D&activityContext=CampaignFlowRoot.CampaignFlowConstructionView.ReachWidgetRpcManager.SendDisplayCampaignConstructionComixRequest' --compressed";
new File(fileName).delete();
BufferedWriter writer = new BufferedWriter(new FileWriter("out.sh", true));
writer.append(s);
writer.close();
Runtime.getRuntime().exec("chmod u+x "+fileName);
String s1 = runCliCommand("./" + fileName);
Integer impression = Integer.parseInt(s1.substring(s1.indexOf("\"8\":\"") + 5).substring(0, s1.substring(s1.indexOf("\"8\":\"") + 5).indexOf("\"")));
return "update googleinmarketcategory set reach = " + impression + " where id = " + id + ";";
} catch (Exception ex) {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.joining("\n"));
BufferedWriter writer = new BufferedWriter(new FileWriter("result.sql", true));
writer.append(collect);
writer.close();
int i = 9;
}
public static String runCliCommand(String arguments) {
try {
ProcessBuilder processBuilder = new ProcessBuilder(arguments);
Process p = processBuilder.start();
p.waitFor();
if (p.exitValue() != 0) {
String errorResult = new BufferedReader(new InputStreamReader(p.getErrorStream())).readLine();
throw new RuntimeException(errorResult);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder result = new StringBuilder(reader.readLine());
String line;
while ((line = reader.readLine()) != null) {
result
.append("\n")
.append(line);
}
return result.toString();
} catch (IOException | InterruptedException | NullPointerException ex) {
ex.printStackTrace();
throw new RuntimeException("nonono");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment