Text File Index? - ios

Good afternoon,
I am wanting to create a a Text file with a many different paragraphs. I want to show a different one everyday. Is there a way to create s sort of index and display a new paragraph each day?
I crated the app already, and the way I am updating is by going into my server and editing the text file and then downloading it into the app, and I have to update it every day and I don't want to do that anymore. I have about 2 years worth of daily paragraphs that I can simply have them all in a text file. I'm not sure if an index is the right approach to this.
I want to be able to have like a huge list of text paragraphs and then displaying a different one each day. Is there any way to do this? I am open to different suggestions! I just want to get it to work! Maybe someone can guide me through the right path.
Thank you!

First, start with the simplest thing that could possibly work:
Make a text file with all your paragraphs. Download the entire file into your app. In your app, split the file into paragraphs, choose one at random, and display it.
Now, if the above proves too slow, then consider optimising it. You could:
After downloading the text file (the first time), read through the file once and create an index with the offset of the start of each paragraph. Then, choose an index entry at random, seek to that point in the text file, read the paragraph, and display it.
Or, you could:
Create the index on the server and download it along with the text file. That saves the app from having to create the index itself.

There are probably easier/better ways to do this, but here's what I'd do...
I'd reorganize your text file into a CSV with two columns. The column on the left has the date paragraph should be displayed (in an easy to parse format), and the column on the right has the actual paragraph. When the app is first launched, it goes to the web, downloads and parses this whole file.
In your app, store these paragraphs in an NSDictionary, using the date as the key, and the paragraph as the value.
Now encode this NSDictionary to disc.
From now on, you don't need to redownload/reparse the file. You can just check in that dictionary, find the entry with the right date, and display that.
Now, ideally, you'd want your server to be able to tell your app when the file was last updated, and for your app to keep track of when it last downloaded the file. Any time the server's last update date is more recent than the app's last download date, the app should redownload, reparse, resave the file.
If you don't want to store the dates, you can simple put the paragraphs in a line separated .txt file. When you read the file in, you can store each paragraph into a separate array index very simply by doing something like this:
NSArray *paragraphs = [myTextDocContents componentsSeparatedByCharactersInSet:
[NSCharacterSet newLineCharacterSet]];

Related

How to create a file with two entries in COBOL?

I have two files, the first one has the date and the second one has multiple registers.
I want to create something like this:
Input File 1:
20200509
Input File 2:
0000001
0000002
0000003
Output
202005090000001
202005090000002
202005090000003
Thank u.
Build a record of two fields. I will not give you picture clauses.
Read file one and populate field one. (end of field one stuff).
Read file two and for each record, populate field two and write an output record.
Field one never changes?
Look into JOINKEYS (FILL?) if you get a moment and your shop has it.
And the record in File one should probably be a parameter.
Yes you will need to open and close the files, use filestat, and understand what a priming read is.
If you don't mind bad style and ANS COBOL c. 1972 see
https://github.com/mckenzm/join2files/blob/main/stackex1.cbl
(No filestat, no exception (empty file) handling.)

Google Sheets import multiple HTML table images

Summary
I'm looking to import a data table from a website that does not appear to have an API. The table is broken down to various images and text. The goal is to have all of the content available in a table to then reference for other sheets.
Issue
When I pull in the data, I get some of the text, none of the other images, and a reference to another table. I looked up some options, but none of them yielded anything but blank cells.
I also tried to use the =IMAGE() formula with a direct link to the images URLs, but there is a portion of the URL that is specific to the unit's release date, and as such, too dynamic to account for.
Excel Formula
=IMPORTHTML("https://gamepress.gg/pokemonmasters/database/sync-pair-list","table",3)
Unfortunately without an API it is going to be difficult to achieve what you aim here. These are the main reasons why:
PROBLEMS AND WORKAROUNDS
This table has nested tables that therefore need to be accessed separately. If you take a look at: =IMPORTHTML("https://gamepress.gg/pokemonmasters/database/sync-pair-list","table",4)
you will see how the table 4 of this HTML page is the stats of a random character of the main table. If you go for 5 or 6 you will realise that the nested tables are not even numerically ordered and that you cannot access them by accessing to the main table (i.e mainTable[0].nestedTable). A hard working approach to do this is to go one by one finding their corresponding stat table and placing next to it. For this I recommend extracting only the name field of the main table to be able to align each stat to their character. You can simply do this using:=INDEX(IMPORTHTML("https://gamepress.gg/pokemonmasters/database/sync-pair-list","table",3),0,1). You can find out more about INDEX here
IMPORTHTML cannot access images nor links so it will be very difficult to get the images in the last columns. A way to solve this is by using as you mentioned the image with its url like this: =IMAGE("https://gamepress.gg/pokemonmasters/sites/pokemonmasters/files/styles/30x30/public/2019-07/Electric.png?itok=fkRfkrFX"). You can find more info about inserting images here
CONCLUSION
To sum up, there is no easy way to solve this problem. The closest you can get is by:
Importing the name column.
Figuring out which tables belong to which character and placing them with next to their name.
Getting the image url of each weakness and type and add it to each character.
I am sorry this site does not have an API to make things smooth, good luck with your project and let me know if you need anything else or if you did not understand anything.
Here you can find more information about IMPORTHTML

Getting inconsistent tab delimiter width when pasting from Google docs spreadsheet

I am trying to create a gadget for some people, where all they need to do is really copy the contents of a spreadsheet, then paste it in a textbox, which will in turn create a nice table for them to embed in their articles.
I managed to do everything, however Google docs, when copying and pasting data in a text editor, seems to get the size (width) of the tab delimiter wrong between values. So, instead of getting 4 spaces that is the default, i am getting 2 in some cases and so far i managed to find out that the reason is that some of the cells contain strings with spaces. For some reason, this seems to confuse Google docs, thus supplying wrong spacings, which in turn, ruin my script.
I know i can use comma separated values here, but the issue is we are trying to give people the ability to simply copy and paste. Look at the example output below:
School Name Location Type No. eligible pupils
In this example, School Name is one cell, Location is another, Type is another and No. eligible pupils is the last one. It is clear that the first cell does not have the necessary space on the right.
Any ideas? I thought about converting all blank spaces that take more than 1 space to commas, but this might lead to a situation users might actually use 2... which would not work again.
For some reason, it was the code editor that was actually not showing the tabs right. Using a regexp and another code editor (vim) showed that all of them were actual tabs. :)

Writing at the top of the CSV file (or alternatively, how to reverse one)

I need to append data to a CSV file containing monthly records provided by a third party that's in an illogical order, meaning the newest records are at the top. I need to add a new line every month, but I haven't found a way to append at the top, nor to cleverly reverse it.
One way, I realize, would be to loop the lines in reverse order and write to a new file, but that seems stupid. Surely there must be a smarter answer.
Is there?

Automatically updating Data Validation lists based on user input

I have a very large data set (about 16k rows). I have 10 higher level blocks and within each block I have 4 categories (10 rows for each) which use Data Validation lists to show items available in each category. The lists should automatically update based on user input. What I need your help with is that I want to use the same data set for each block and preferably a least calculation/size intensive approach. I have put together a sample file that outlines the issue with examples.
Sample File
Thank you for your help in advance.
Okay, I've found something, but it can be quite time consuming to do.
Select each range of cells. For instance, for the first one, select B3:B18 and right click on the selection. Find 'Name a Range..." and give it the name "_FIN_CNY". Repeat for all the other ranges, changing the name where necessary.
Select the first range of cells to get the data validation, and click on "Data validation", pick the option "Allow: List" (you already have it) and then in the source, put the formula:
=INDIRECT($G$4&"_CNY")
$G$4 is where the user will input. This changes as you change blocks.
_CNY is the category. Change it to _CNY2 for the second category.
Click "OK" and this should be it. Repeat for the other categories.
I have put an updated file on dropbox where you can see I already did it for the data of _FIN for categories CNY, CNY2 and INT and did the one for _GER as well. You'll notice the category of INT for _GER doesn't work, that's because the Named Range _GER_INT doesn't exist yet.

Resources