Skip to content

Commit 6f7d557

Browse files
author
crothhass
committed
add tennis scores
1 parent d61b1a6 commit 6f7d557

File tree

2 files changed

+94
-14
lines changed

2 files changed

+94
-14
lines changed

app/src/main/java/huti/sportinfo/modules/ModuleTennis.java

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public void getGames(String htmlsource) {
5151

5252
String[] split = htmlsource.split("\n");
5353
for (int i = 0; i < split.length; i++) {
54-
55-
5654
if (split[i].indexOf("<th>Spielbericht</th>") >= 0) {
5755
// Start der Tabelle
5856
bolGameOpen = true;
@@ -73,8 +71,7 @@ public void getGames(String htmlsource) {
7371

7472
} else if (bolGameOpen && (split[i].indexOf("<td>") >= 0 || split[i].indexOf("<tr>") == -1)) {
7573
tdcounter++;
76-
if (tdcounter == 3)
77-
{
74+
if (tdcounter == 3) {
7875
// Datum und Uhrzeit
7976
datum = Html.fromHtml(split[i]).toString().trim();
8077

@@ -87,21 +84,22 @@ public void getGames(String htmlsource) {
8784
e.printStackTrace();
8885
}
8986
datum = outFormat.format(date);
90-
}
91-
else if (tdcounter == 5)
92-
{
87+
} else if (tdcounter == 5) {
9388
// heim
9489
heim = Html.fromHtml(split[i]).toString().trim();
95-
}
96-
else if (tdcounter == 8)
97-
{
90+
} else if (tdcounter == 8) {
9891
// gast
9992
gast = Html.fromHtml(split[i]).toString().trim();
100-
}
101-
else if (tdcounter == 11)
102-
{
93+
} else if (tdcounter == 11) {
10394
//Log.d("TENNISSPIEL",heim+" gegen "+gast + " am "+datum);
10495
// scores
96+
String punktestring = Html.fromHtml(split[i]).toString().trim();
97+
if (punktestring.trim() != "" && punktestring.indexOf(":") >= 0)
98+
{
99+
String[] punktearr = punktestring.split(":");
100+
punkteheim = Integer.parseInt(punktearr[0]);
101+
punktegast = Integer.parseInt(punktearr[1]);
102+
}
105103

106104
// speichern
107105
int intheimspiel = 0;
@@ -172,7 +170,89 @@ public void getTable(String htmlsource) {
172170

173171
String[] split = htmlsource.split("\n");
174172
for (int i = 0; i < split.length; i++) {
173+
if (split[i].indexOf("<th class=\"center\">Games</th>") >= 0) {
174+
// Start der Tabelle
175+
bolTableOpen = true;
176+
//Log.d("TENNISTABELLE START", split[i]);
177+
} else if (bolTableOpen && split[i].indexOf("</table>") >= 0) {
178+
// Ende der Tabelle
179+
bolTableOpen = false;
180+
//Log.d("TENNISTABELLE ENDE", split[i]);
181+
break;
182+
} else if (bolTableOpen && split[i].indexOf("</tr>") >= 0) {
183+
// Reset neue Zeile
184+
tdcounter = 0;
185+
tabellennr = 0;
186+
punkte = 0;
187+
intfavorit = 0;
188+
//Log.d("TENNISTABELLE ZEILE", split[i]);
189+
} else if (bolTableOpen && (split[i].indexOf("<td>") >= 0 || split[i].indexOf("<tr>") == -1)) {
190+
tdcounter++;
191+
192+
if (tdcounter == 7) {
193+
// nummer
194+
//Log.d("TENNISTABELLE Rang", split[i]);
195+
tabellennr = Integer.parseInt(Html.fromHtml(split[i]).toString().trim());
196+
}
197+
else if (tdcounter == 12) {
198+
// mannschaft
199+
//Log.d("TENNISTABELLE Mannscha", split[i]);
200+
mannschaftname = Html.fromHtml(split[i]).toString().trim();
201+
}
202+
else if (tdcounter == 22) {
203+
// punkte
204+
//Log.d("TENNISTABELLE Punkte", split[i]);
205+
String punktestring = Html.fromHtml(split[i]).toString().trim();
206+
String[] punktesplit = punktestring.split(":");
207+
punkte = Integer.parseInt(punktesplit[0]);
175208

209+
210+
ContentValues values = new ContentValues();
211+
212+
// haben wir unsere eigene Mannschaft?
213+
long idmannschaft = 0;
214+
if (mannschaftname.indexOf(kennung) >= 0) {
215+
intfavorit = 1;
216+
} else {
217+
// check ob gegner schon angelegt ist
218+
String sqlget = "SELECT idgegner FROM gegner AS g";
219+
sqlget += " WHERE idfavorit=" + idfavorit + " AND bezeichnung = '" + mannschaftname + "'";
220+
Cursor sqlresult = connection.rawQuery(sqlget, null);
221+
if (sqlresult.getCount() > 0) {
222+
sqlresult.moveToFirst();
223+
idmannschaft = sqlresult.getInt(0);
224+
} else {
225+
values.put("idfavorit", idfavorit);
226+
values.put("bezeichnung", mannschaftname);
227+
idmannschaft = connection.insert("gegner", null, values);
228+
}
229+
}
230+
231+
//check ob tabelle angelegt ist
232+
long idtabelle;
233+
String sqlgettablerow = "SELECT idtabelle FROM tabellen AS t";
234+
sqlgettablerow += " WHERE intfavorit=" + intfavorit + " AND idfavorit=" + idfavorit + " AND idmannschaft=" + idmannschaft;
235+
Cursor sqlresultgame = connection.rawQuery(sqlgettablerow, null);
236+
if (sqlresultgame.getCount() > 0) {
237+
sqlresultgame.moveToFirst();
238+
idtabelle = sqlresultgame.getInt(0);
239+
// update table number and score
240+
values = new ContentValues();
241+
values.put("punkte", punkte);
242+
values.put("tabellennr", tabellennr);
243+
connection.update("tabellen", values, "idtabelle=" + idtabelle, null);
244+
} else {
245+
values = new ContentValues();
246+
values.put("idfavorit", idfavorit);
247+
values.put("intfavorit", intfavorit);
248+
values.put("idmannschaft", idmannschaft);
249+
values.put("punkte", punkte);
250+
values.put("tabellennr", tabellennr);
251+
idtabelle = connection.insert("tabellen", null, values);
252+
//Log.d("SPORTINFO", "INSERT Spiel "+idspiel);
253+
}
254+
}
255+
}
176256
}
177257
connection.close();
178258
database.close();

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<item>INSERT INTO favoriten(intsportart,intaktiv,bezeichnung,kurzbezeichnung,kennung,urlspiele,urltabelle,farbe)
105105
VALUES (1,1,\'TTC Klingenmünster H1\',\'TTC KLM Herren\',\'Klingenm\',\'http://tt-info.de/cache/1204/x_sppl_ges_c_16088.html\',\'http://tt-info.de/tt-online.cgi?akt=1006&amp;b_u_0=1100&amp;b_u=&amp;m_nummer=16088&amp;spk_nummer=1204&amp;srq=&amp;c_t=\',\'39529A\');</item>#
106106
<item>INSERT INTO favoriten(intsportart,intaktiv,bezeichnung,kurzbezeichnung,kennung,urlspiele,urltabelle,farbe)
107-
VALUES (2,0,\'TC Herxheim H1\',\'TC Herxheim H1\',\'Herxheim\',\'http://rl-tvrp.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/teamPortrait?team=1751062&amp;championship=PF+2015\',\'http://rl-tvrp.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/teamPortrait?team=1751062&amp;championship=PF+2015\',\'39529A\');</item>
107+
VALUES (2,0,\'TC Herxheim H1\',\'TC Herxheim H1\',\'Herxheim\',\'http://rl-tvrp.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/teamPortrait?team=1751062&amp;championship=PF+2015\',\'http://rl-tvrp.liga.nu/cgi-bin/WebObjects/nuLigaTENDE.woa/wa/groupPage?championship=PF+2015&amp;group=1\',\'39529A\');</item>
108108
</string-array>
109109

110110
</resources>

0 commit comments

Comments
 (0)